I want to deploy an Autopilot profile with a custom device naming convention that uses the user’s UPN. How can I achieve this?
Question
I want to deploy an Autopilot profile with a custom device naming convention that uses the user’s UPN. How can I do that, is there any powershell scripts should i write or is there any trick i can use
Answer ( 1 )
Hi Rakesh Kumar,
You cannot dynamically use the signed-in user’s UPN directly in the Autopilot device name template.
* The Autopilot profile device name template supports only serial number (%SERIAL%) and random characters (%RAND:x%) placeholders.
* The UPN (or username) is not known at the time the profile is applied during OOBE, so Autopilot can’t insert it into the device name.
But there is also a workaround
* Use Intune dynamic naming with a post-enrollment script (most common approach)
Set a generic device name in your Autopilot profile (e.g., AUTO-%SERIAL%).
* After the user logs in, push a PowerShell script via Intune to:
Get the UPN of the primary user ((Get-MsolUser) or dsregcmd /status can help determine this).
* Rename the device to include the UPN (e.g., Rename-Computer -NewName “$env:USERNAME-LT”).
* A force restart is required to apply the name.
PowerShell Command :
$PrimaryUser = (Get-WmiObject -Class Win32_ComputerSystem).UserName
$NewName = $PrimaryUser.Split(“”)[1] + “-LT”
Rename-Computer -NewName $NewName -Force -Restart