top of page
Search

(199) Microsoft Intune - Rename devices with PowerShell

  • Writer: Mr B SOE way
    Mr B SOE way
  • 6 hours ago
  • 2 min read

Previous posts I have covered with setting a hostname or prompt for computer name.


Manually renaming a single device is simple, but managing a large fleet requires automation for efficiency. While the standard CSP method exists, it can be inconsistent—especially regarding console reporting.


To solve this, I’m sharing a PowerShell script that integrates with Microsoft Intune to streamline and automate your device renaming process.


This script detects the type of device used for a virtual machine or physical machine, it will retrieve the serial number and add the prefix: IGG


To prepare the win32 app, you will need:



Just rename the prefix to whatever you like under $Prefix

#Variables
    $Date = Get-Date
    $CurrentName = (Get-CimInstance -ClassName Win32_ComputerSystem).Name
    $Prefix = "IGG"
    $Logs = "C:\ProgramData\MrBSOEWay\logs\RenameComputerToIGG.log"

#Delete old Logs files
    Remove-Item -Path $Logs -Force

#Computer Name 
    Write-Output "$($Date) : The current computer name is $($CurrentName)" | Tee-Object -FilePath $Logs -Append

#Check Platform type
    $ComputerType = (Get-ComputerInfo).CsSystemFamily
    If($ComputerType -eq "Virtual Machine")
        {
            Write-Output "$($Date) : Platform detection - $($ComputerType) : using an automatically generated computer name." | Tee-Object -FilePath $Logs -Append
            $Serial = (Get-CimInstance win32_bios).serialnumber
        }
    else
        {
            Write-Output "$($Date) : Platform detection - $($ComputerType) :  using the service tag to generate the computer name." | Tee-Object -FilePath $Logs -Append
            $Serial = (Get-CimInstance win32_bios).serialnumber
        }

#Change Computer Name
    Write-Output "$($Date) : The script change the computer name because it's not compliant with the naming convention" | Tee-Object -FilePath $Logs -Append
    Rename-Computer -NewName "$($Prefix)$($Serial)" -Force
    Write-Output "$($Date) : The new computer name is $($Prefix)$($Serial)" | Tee-Object -FilePath $Logs -Append
        
#Send message to user for request computer restart & reboot
    Shutdown -r -t 120 -f -c "Your administrator has implemented changes. To finalize the process, we will reboot your computer in 2 minutes."

if (test-path "C:\ProgramData\MrBSOEWay\logs\RenameComputerToIGG.log"){"Installed"} 

Once the app is deployed, end users will receive this message:











After the device has been restarted, on logon you will notice the hostname has changed.























Similarly with that on the Intune portal, it will reflect the name change.


 
 
 

Comments


bottom of page