Rename devices with PowerShell and Microsoft Intune

Renaming a device manually is quick and easy when we only have one device to fix. But when it comes to doing a large number of devices, then it is better to automate this action.

Today, there is the method via CSP but which can have a rather random behavior, in particular on the reporting, console side.

I therefore share with you a PowerShell script which, deployed with Microsoft Intune, will allow you to quickly rename your machines.

Script overview

This script detects the type of device used: 
  • If it's a virtual machine, it takes the defined prefix (CCMT in my example) and adds a numeric complement generated with Get-Random command
  • For physical machines, it retrieves the serial number and adds the prefix (CCMT in my example)
The user is informed that his device has received changes and that it will restart automatically in a few minutes.

The script is available on Github : Link

Script integration & deployment


The prerequisites are:
  • Convert script to .intunewin app
  • Create a dynamic group to group all the devices to be renamed

Create devices dynamic group

  • Go to
  • Click Groups
  • Select New Group
  • Complete Group name field
  • Membership type, select Dynamic Device
  • Add dynamic query and click Save

Create and deploy the script with Microsoft Intune

After coverted script to intunewin package,
  • Go to
  • Select Windows and click Add
  • App type, select Windows App (Win32) and click Select
  • Select Win32 app package file and click OK
  • App information, complete Publisher field and click Next
  • Specify the commands to install and uninstall this app:
    • Install : powershell.exe -ExecutionPolicy Bypass -File .\Rename_Computer.ps1
    • Uninstall : add any value to go to the next step
  • Requirements :
    • Select operating system architecture
    • Select minimum operating system
  • click Next
  • Detection rules : 
    • Select Manually configure detection rules
    • Click Add
    • Rule type, select File
    • Path : C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\
    • File or folder : RenameComputer.log
    • Detection method : File or folder exists
  • Click OK
  • Dependencies, click Next
  • Supersedence, click Next
  • Assignements, Select the dynamic group that you previously created and click Next
  • Review + Create, click Create


A log is available on the workstation that received the script:
  • C:\ProgramData\Microsoft\IntuneManagementExtension\Logs\RenameComputer.log

Microsoft Intune console side, you have access to reporting related to application deployments.

Popular posts from this blog

How to implement Applocker with Microsoft Intune

How to reset computer in OOBE mode

Microsoft Intune, Uninstall Win32 app with the company portal