Bulk Renaming of Intune Devices

Landi 6 Reputation points
2022-11-14T16:15:40.017+00:00

I have a new Intune Naming convention to Implement I'm have been trying to find an easy way to rename 1000 WIN10 devices from a .csv file using either Intune powershell scripts or Microsoft graph APIs.All devices are enrolled on intune.
The renaming function on the Endpoint Management has limited capabilities
Any help would be greatly appreciated.

Microsoft Intune
Microsoft Intune
A Microsoft cloud-based management solution that offers mobile device management, mobile application management, and PC management capabilities.
4,989 questions
{count} vote

1 answer

Sort by: Most helpful
  1. Fiona Matu 86 Reputation points Microsoft Employee
    2024-02-18T12:00:46.64+00:00

    Hi @Landi, There is a beta MS Graph API:

    PATCH /deviceManagement/managedDevices/{managedDeviceId}
    

    that you can use to perform this task though we always warn against the use of beta APIs in production since they are subject to change. However, renaming a device in Intune doesn't actually change the device's hostname in the OS, it just changes the device's name in Intune. Here is the sample code to rename a device using Graph API in PowerShell:

    $accessToken = 'access_token' # Use your access token here
    $deviceId = 'device_id' # Use your device id here
    $newName = 'new_device_name' # Use the new device name here
    
    $uri = "https://graph.microsoft.com/beta/deviceManagement/managedDevices/$deviceId"
    $body = @{
      deviceName = $newName
    } | ConvertTo-Json
    
    $headers = @{
      'Authorization' = "Bearer $accessToken"
      'Content-Type' = 'application/json'
    }
    
    Invoke-RestMethod -Uri $uri -Method PATCH -Body $body -Headers $headers
    
    

    To get the access token, you can follow the instructions in this document: Get access on behalf of a user. To get the deviceId, you can use the List managedDevices API. You will however need to loop through your csv file, get each device id and then call the API to rename each device. You should also handle rate limits as per Microsoft's documentation. Remember that you must have the necessary permissions to perform these operations. The required permissions are DeviceManagementConfiguration.ReadWrite.All.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.