Intune – Rename iOS devices with Intune Powershell SDK

This will be the first post in a series where I will cover Graph API and in this specific post how we can rename iOS devices that’s being managed by Intune in a more automatic way then going in to the Intune portal and manually renaming them. There’s several levels of automation that can be achieved ranging from manual automation (Manually running a script) to full blown automation with the help of either schedule task running on a computer or using Azure automation and there’s a few challenges along the way that needs to be taken under consideration and ironed out.

A couple of weeks ago Microsoft announced bulk renaming of devices with DEP (Deployment enrollment program) and you can now configure the DEP profile to rename the device during enrollment.

https://docs.microsoft.com/en-us/intune/whats-new#bulk-device-naming-when-enrolling-corporate-ios-devices

Bulk device naming when enrolling corporate iOS devices

When using one of Apple’s corporate enrollment methods (DEP/ABM/ASM), you can set a device name format to automatically name incoming iOS devices. You can specify a format that includes the device type and serial number in your template. To do so, choose Intune > Device enrollment > Apple enrollment > Enrollment program tokens > Select a token >Create profile > Device naming format. You can edit existing profiles, but only newly synced devices will have the name applied.

This is a great feature but won’t solve the issue for already enrolled devices. These you still need to either manually rename or factory reset to re-enroll once the configuration is set.

In this post we will take a look at using the Intune Powershell SDK to rename iPad’s which in my opinion has the lowest barrier for entry and the least amount of work/complexity to rename iPad’s in Intune on a large scale without needing to do manually rename every iPad within the Intune portal (See picture below). To do this we are going to use the Intune Powershell SDK and for more info about that and how to get started with it check out my post here: https://timmyit.com/2018/10/22/intune-powershell-sdk/

Overview

The script is fairly simple due to the fact that we are using the Intune Powershell SDK that handles all the webrequest to Graph API “behind the scenes” with the help of the cmdlets thats been created for this powershell module.

Once you downloaded and Installed the Intune Powershell SDK module (If you dont know how to do this check out my other blog post here https://timmyit.com/2018/10/22/intune-powershell-sdk/ Then you can to use the sample script provided below.

Side note.

When you start an iPad for the first time or do a factory reset the default name will be “iPad”. Some organization doesn’t want to use that name for different reasons and if you would like to have another name then serial number of the device then you need to be able to get that information and map that to a unique iOS device.

Rename one specific iOS device

If you want to change the name of one specific iOS device you can use the sample below. We need to identify the device we want to change and the easiest way is to do that by serial number. Change the serial number between the single quotation mark from XXXXXXXXXX to the specific serial number for the iPad you want to change as seen in the picture below. Remember that we are only able to rename iOS devices which are supervised thats why we are only filtering on Serial number and if the device is supervised.

In this example we are changing the name from iPad or iPhone to the serial number of the device.

Important Note. 

As per today there’s a bug in the SDK which causes the Update-IntuneManagedDevice cmdlet not to work as intended when trying to rename a deivce using the cmdlt. Microsoft is aware of the problem and an issue has been raised on githib https://github.com/microsoft/Intune-PowerShell-SDK/issues/29

The good thing is that there’s a work around and that’s to use the Invoke-MSGraphRequest cmdlt from the SDK.


Connect-MSGraph

$Device = Get-IntuneManagedDevice -Filter "contains(serialNumber,'XXXXXXXXXX')"

$DeviceID = $Device.id
$Resource = "deviceManagement/managedDevices('$DeviceID')/setDeviceName"
$graphApiVersion = "Beta"
$uri = &"https://graph.microsoft.com/$graphApiVersion/$($resource)"

$JSONName = @"
{
deviceName:"$($Device.serialNumber)"
}
"@

Invoke-MSGraphRequest -HttpMethod POST -Url $uri -Content $JSONName

Once we ran the script and go back in to the Intune console, we can find the device and see that there’s a client action pending to rename the device

Rename all company owned and supervised iOS devices

The script will start with importing the module then connect to Graph API and here you will need to enter your credentials to your tenant. Then we will get all iOS devices that’s being managed by Intune and is company owned and supervised.  Once that’s done we will go through each devices that got collected and check to see if the current name is equal to the Serial number of the device, if it is nothing will happen and if it’s not we will rename that devies and set the new name to be the serial number of the device.

 Connect-MSGraph
 $AlliOSDevices = Get-IntuneManagedDevice -Filter "(contains(operatingsystem, 'iOS')%20and%20isSupervised eq true)"
 Foreach ($AlliOS in $AlliOSDevices)
 {
 $DeviceID = $Device.id
 $Resource = "deviceManagement/managedDevices('$DeviceID')/setDeviceName"
 $graphApiVersion = "Beta"
 $uri = "https://graph.microsoft.com/$graphApiVersion/$($resource)"
 $JSONName = @"
 {
 deviceName:"$($Device.serialNumber)"
 }
 "@
 if ($AlliOS.deviceName -ne $AlliOS.serialNumber)
 {
 Invoke-MSGraphRequest -HttpMethod POST -Url $uri -Content $JSONName
 }
 }
 

Leave a comment or question in the comment section below.

That’s all for now and until next time, cheers !

Don’t forget to follow me on twitter

[twitter-follow screen_name=’Timmyitdotcom’]

And you can also find me blogging over at http://blog.ctglobalservices.com/

3 comments

  1. Hey Tim,

    Is it possible to bulk upload Asset tags as device names ?
    We have thousands for iOS devices being enrolled to individuals but would like to change the device names for all with bulk update. Each iOS device will have a unique asset tag. Can this be done?

    thanks

    atul

    1. yes it can be done, however you need some kind of logic to cross-reference the serial number of the iOS device and the asset tag to make sure you give the correct iOS device the correct name. The way I would go about is to create a Azure automation job that renames the device.

Leave a Reply