Rename Computer via Intune - mattnovitsch/M365 GitHub Wiki

Summary

This script can be used to rename your computer with adding the device serial number in the name. I have had this request come up with several customers looking to do this during the enrollment process in Intune and/or AutoPilot. As the Intune does support serial number, autopilot doesn't support variables such as %SERIAL% and only support prefixes for the computer name. The plan would be to get the device to join with a temporary name then have it rename once it has fully enrolled with Intune. The renamecomputer.ps1 script will rename the device to Lenovo. Please feel free to edit the script to whatever 6-character prefix you want. I also added a restart-computer command in there that is commented out, if you want to force the restart right after the change you can but I would just let it wait until the user does it on their own.

Note

Active Directory limits to 15-characters so please make sure your prefix and serial number don't exceed that or it will fail. It's worth to note that if you don't have access to the domain controller for hybrid join this could cause domain trust issues with those devices.

References

Accounts Configuration Service Provider Deploy hybrid Azure AD-joined devices by using Intune and Windows Autopilot

Prerequisite

RenameComputer.ps1

Steps

  1. Navigate to Microsoft Endpoint Manager
  2. Navigate to Devices > Windows > PowerShell Scripts then click the +Add button RenameComputer1
  3. Name your script, I'm using "Rename Computer" for this example, click next to continue RenameComputer2
  4. Select the RenameComputer.ps1 file then select next RenameComputer3
  5. Scope the script appropriately, in my lab I only have one scope for windows devices. Click Next to continue RenameComputer4
  6. The assignment is where it gets tricky. We only want to target the devices you want to rename. You can use your autopilot group but if you have devices already deployed it could rename devices that you don't want to. For safety reasons, I recommend creating a group that you want to target to rename and add it to the assignment. Click Next once you have selected your group RenameComputer5
  7. Review to make sure you have the correct script and group assigned. Click Add once you have verified everything RenameComputer6

Additional Example using OU to name your endpoints

I've also had the ask if we can do the rename depending on the OU where the computer object is located. You can you have to load RSAT tools on the device and import the Active Directory module on the device. I have a sample of the script here.