This is a short post about how to use the serial number of your computer as computer name.
During a deployment, maybe a cloud deployment of your Windows 10/11 clients (not talking about Autopilot), you will have to define a computer name. The easiest way to get a random and never the same name, is to use the serial number.
Not all vendors do use the same style of the serial number. For example HP uses 11 characters while Fujitsu only has 10 (depends on the models as well). So let’s get started:
First we need to get the serial out of the device. I always use Get-ComputerInfo
Get-ComputerInfo
Be aware, that there is a small bug in the Paramater BiosSerialNumber. On some Windows versions (I guess all Windows 10) the parameter is called (missing an “i”):
BIOSSeralNumber
As a next step, you may would like to have a prefix within your computer name. If you decide to use a prefix, put that in a variable such as:
$prefix = "LDC-"
So let’s put it together using the command without a bug. This works on Windows 11. And then put the serial in to the variable $serial:
$prefix = "LDC-"
$serial = Get-ComputerInfo | Select-Object BiosSerialNumber
$serial = $serial.BiosSerialNumber
As a computer name (NetBIOS) has a limit of 15 characters, we need to shorten the serial to, let’s say, 10 characters (0, 10), starting from the beginning (0, 10):
$serial = $serial.substring(0, 10)
Now let’s put the computer name together into the $computername variable using the $prefix and the $serial variables:
$computername = $prefix + $serial
The result will looks like that (based on your hardware and serial):
LDC-01812637465
Finally run the rename computer cmdlet and reboot the machine. You computer has a new name with a prefix and a part of your serial.
Rename-Computer -NewName $computername -Force -ErrorAction SilentlyContinue
Let me know what you think. Cheers!