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
.