Skip to main content

Bulk Renaming Autopilot Devices with Graph API


Purpose

This procedure provides the steps to bulk rename existing Autopilot devices using the Microsoft Graph API, ensuring that devices conform to organizational naming conventions after they have been registered in Intune.


Scope

This procedure applies to IT administrators managing existing Windows Autopilot devices in Microsoft Endpoint Manager (Intune). It assumes devices are already imported into the Autopilot service.


Prerequisites

Before proceeding, ensure you have:

  • Familiarity with the Microsoft Graph PowerShell SDK.
  • The WindowsAutoPilotIntune PowerShell module installed.
  • Permissions to modify device objects in Intune/Entra ID (Device.ReadWrite.All or similar).

Procedure and Guidelines

Step 1: Collect Device Information for Renaming

Purpose: To gather the serialNumber and current ComputerName from a set of devices and export this data to individual CSV files. This maps serial numbers to the names that will be used as a base for renaming.

Instructions: Run the following script on each device you intend to rename.

Script:

# Create a directory if it doesn't exist
New-Item -Type Directory -Path "C:\Temp\DeviceInfo" -Force

# Get NetBIOS name and serial number
$computerName = $env:COMPUTERNAME
$serialNumber = (Get-WmiObject -Class Win32_Bios).SerialNumber

# Export to CSV
$outputFile = "C:\Temp\DeviceInfo\DeviceInfo_${computerName}.csv"
[PSCustomObject]@{serialNumber = $serialNumber; ComputerName = $computerName} |
Export-Csv -Path $outputFile -NoTypeInformation -Force

Write-Host "Device info has been saved to: $outputFile"

After running this on all target devices, transfer the DeviceInfo_*.csv files to a single folder on your admin workstation.

Step 2: Consolidate Device Information into a Single CSV

Purpose: To merge all individual DeviceInfo_*.csv files into a single master file that the bulk renaming script can process.

Instructions:

  1. Place all DeviceInfo_*.csv files into a single folder (e.g., C:\Temp\Consolidate).
  2. Run the following PowerShell script to merge them.

Script:

Param(
[String]$SourcePath = "C:\Temp\Consolidate"
)

# Consolidate CSV files
Get-ChildItem -Path $SourcePath -Filter "DeviceInfo_*.csv" |
Select-Object -ExpandProperty FullName |
Import-Csv |
Export-Csv -Path "$SourcePath\ConsolidatedDeviceInfo.csv" -NoTypeInformation -Force

Write-Host "All DeviceInfo files have been combined into ConsolidatedDeviceInfo.csv"

Step 3: Execute Bulk Rename with Microsoft Graph API

Purpose: To read the consolidated device list and update the displayName for each Autopilot device object via the Graph API.

Script:

# Install the necessary module if not already installed
If (-not (Get-Module -ListAvailable -Name WindowsAutoPilotIntune)) {
Install-Module -Name WindowsAutoPilotIntune -Force -Scope CurrentUser
}

# Connect to Microsoft Graph. You will be prompted to sign in.
Connect-WindowsAutopilotIntune

# --- CONFIGURATION ---
# Path to your consolidated CSV file from Step 2
$csvFilePath = "C:\Temp\Consolidate\ConsolidatedDeviceInfo.csv"
# Naming convention prefix (e.g., your unit's FAMIS code)
$namingSchemePrefix = "CLBA"
$departmentCode = "USER"
# --- END CONFIGURATION ---

# Check if the file exists
if (-Not (Test-Path -Path $csvFilePath)) {
Write-Host "ERROR: The specified file does not exist. Please check the path: $csvFilePath" -ForegroundColor Red
exit
}

# Import CSV data
$devicesToRename = Import-Csv -Path $csvFilePath

# Loop through each device in the CSV
foreach ($device in $devicesToRename) {
$serialNumber = $device.serialNumber
$newDisplayName = "${namingSchemePrefix}-${departmentCode}-${device.ComputerName}" # Example: CLBA-USER-DESKTOP123

try {
Write-Host "Processing device with serial: $serialNumber..."
$autopilotDevice = Get-AutopilotDevice -serial $serialNumber

if ($autopilotDevice) {
Set-AutopilotDevice -id $autopilotDevice.id -displayName $newDisplayName
Write-Host "SUCCESS: Renamed device '$serialNumber' to '$newDisplayName'." -ForegroundColor Green
} else {
Write-Host "WARNING: No Autopilot device found with serial number '$serialNumber'." -ForegroundColor Yellow
}
} catch {
Write-Host "ERROR: Could not rename device with serial '$serialNumber'. Details: $($_.Exception.Message)" -ForegroundColor Red
}
}

Step 4: Verify Device Rename

Purpose: To confirm that a device's name has been updated correctly in the Autopilot service.

Script:

# Ensure you are connected via Connect-WindowsAutopilotIntune

# --- CONFIGURATION ---
$serialNumberToVerify = "SERIAL_OF_A_DEVICE_YOU_RENAMED"
# --- END CONFIGURATION ---

try {
$device = Get-AutopilotDevice -serial $serialNumberToVerify
if ($device) {
Write-Host "Device Found:" -ForegroundColor Cyan
Write-Host " Serial Number: $($device.serialNumber)"
Write-Host " Display Name: $($device.displayName)"
Write-Host " Group Tag: $($device.groupTag)"
} else {
Write-Host "Device with serial '$serialNumberToVerify' not found in Autopilot." -ForegroundColor Yellow
}
} catch {
Write-Host "An error occurred: $($_.Exception.Message)" -ForegroundColor Red
}