Skip to main content

Renaming Windows Autopilot Hybrid Joined Devices

· loading ·
Intune Windows 10 and later Windows Autopilot Hybrid Azure AD PowerShell
Nick Benton
Principal Modern Device Management Consultant and Intune Blogger
Table of Contents


You’ve probably hit the limitation with Windows Autopilot Hybrid Azure AD Join deployments and the device name templates being less than flexible, restricting to only a prefix and, well, that’s it.

You’ve also probably been asked whether you can configure the device name to match an asset tag or another unique bit of information, well this script, adapted from an existing one by Michael Niehaus can help.


The below sections detail the steps carried out to modify the script to work without the need for an Azure web application, and can be deployed locally to rename devices.

Adding the Variables

The post linked above details the steps required to ensure that the computer object itself has the ability to initiate the rename, and the below script has been changed to use existing device information, such as serial, instead of a web service:

  • On-premises domain variable
  • Computer name prefix variable
  • Wait time before restart

This means that it can be deployed to existing environments without the need to deploy, or pay for, an Azure Web App.

The first section details the parameters that can used and updated.

#Sets the variables for the customer
$domain = "onprem.local" #local domain
$ComputerPrefix = "PRE-" #Prefix
$waittime = "60" #sets the restart wait time in minutes

Getting the Device Name

This next section pulls back the serial number and ensures that the computer name is less than 15 characters.

#Get serial and removes commas
$Serial = Get-WmiObject Win32_bios | Select-Object -ExpandProperty SerialNumber
$newName = $ComputerPrefix + $Serial
$newName = $newName.Replace(" ","") #Removes spaces

#shortens name
if ($newName.Length -ge 15) {
    $newName = $newName.substring(0, 15)

The Waiting Game

Using New-TimeSpan we can convert the $waittime variable into whatever time format we need, and as we’re using the shutdown command, we need seconds:

$waitinseconds = (New-TimeSpan -Minutes $waittime).Seconds
Write-Host "Initiating a restart in $waitime minutes"
& shutdown.exe /g /t $waitinseconds /f /c "Restarting the computer in $wait minutes due to a computer name change. Please save your work."

The Whole Thing

The full script can be found here, I would strongly advise testing this prior to pushing it out via Microsoft Intune.


Save the above script and create a new PowerShell script deployment in Microsoft Intune using the following configuration settings, then deploy to a test group of devices.

PowerShell Script

Bingo! another battle won.


Enabling BitLocker and WinRE on failed Windows Devices
· loading
Intune Windows 10 and later BitLocker Security Encryption PowerShell
You may have enabled and configure BitLocker for silent encryption on your Windows 10 Autopilot joined devices, but have you had the headache of devices that don’t have a Windows Recovery Environment (WinRE) configured? Yep? Me too…
Introduction # I’m Nick Benton, an end-user computing specialist with over a decade of experience in consulting, architecture, design, and implementation of modern device management, and enterprise mobility solutions.
Introduction # This site collects usage data using Google Analytics 4 using cookies, giving us insight into the number of people that visit our website.