In this post we will discuss the ways we can rename a device or a group of devices though Intune. We will see two ways:
- one from within Intune Portal that we will use to rename a device and
- one through a remediation script which will be used to rename multiple devices
For the first way we have to locate the wanted device in Intune portal and select Properties. Then click Rename and enter the new name. Here we can also use tokens that indicate device specific characteristics such as {{serialnumber}} or {{rand:x}}.
After we have entered the new name and pressed Rename, a new device action will be shown in the device actions blade, that indicated the rename action we just performed. At the next sync the device will receive the rename action and after a restart the new name will appear.
This is a very convenient way to rename one or two devices, but what happens when someone wants to rename 100+ devices. For this a remediation script that is deployed to the endpoints and perform a rename can be used. Let’s create a script that adds a prefix at each device (e.g. EC from Example Company) and the serial of each device. The final result should be something like ECME47858913025. Of course we can extend this to contain every possible information that we can get from the device such as manufacturer etc.
The general idea is:
- Create the wanted device name (either via a predefined rule or via a device based attribute)
- Execute the Rename-Device cmdlet to rename the device
A very simple approach to this is shown below. In a production environment it is better to use the serial number of the device in the name for better identification and search. By using the serial number we can deploy the below script as a Remediation script that will be ran once a day/week or whenever we want.
We can also extend the script by adding custom logs as described here.
# This is the initials of the organization's name: Example Company -> EC
$prefix = "EC"
# Get the serial using Get-WmiObject
$serial = (Get-WmiObject win32_bios | select Serialnumber).Serialnumber
# Create the final name by concatenating the prefix and the serial
$finalName = $prefix + $serial
# Remove spaces
$finalName = $finalName.replace(' ','')
# here we have to be careful because NETBIOS allows only a 15 digit name a best practice is to keep that # in mind and keep only the first 15 chars of each name. In the majority of the cases, longer names will # not create a problem
$finalName = $finalName.Substring(0,15)
Rename-Computer -NewName $finalName
The detection script will do everything, no need for remediation script here. If we would like to extend this further, we could check in the detection part if the device name matches a specific pattern (e.g. defined prefix + serial number) and if not then execute the remediation part.
After that the script will be deployed to the endpoints and perform the rename (a restart is still required).