Using the suffix of a serial number, TokenizedComputerName

Hi folks,

I’m new to the community and to immy.bot. Hi!
Not sure if there are any donuts but I’ll try to bring some for next time.

For set a computer name, under the TokenizedComputerName section, I can use supported tokens such as $serialnumber but I wanted to know if there was a way I can specify to use the last 6 digits of the serial number.

For instance, a Microsoft Surface Tablet, the serial number is: 063212223451.
I’d like to name the computer $TenantSlug-$FormFactorShort-$SerialNumber
ABC-PC-223451 (the last 6 digits of the serial number).

Does anyone know of a way to do that?
Thanks everyone.

-JM

1 Like

It looks like this is all hashed out in the Resolve-TokenizedComputerName function, and I can’t see that it does anything but the full serial number (although there appears to be some witchcraft in that function so anything is possible!)

To implement this yourself you’d need to duplicate the Resolve-TokenizedComputerName function and call it something else eg Resolve-TokenizedComputerNameCustom, and then duplicate the Configure-ComputerNameAndDomainJoin function and have it call your new function.

Being able to use a custom naming script would be cool - add $Custom as a token, and the have the name of a custom function per-deployment.

But be careful of only using the last 6 digits. HP appears to be fine - they start counting from the right - but Dell’s have a lot of overlap on those last 6 digits. In a fleet of only a few hundred devices at one client i see 11 sets of duplicates on the last 6 digits, and in one case 8 computers share the last 6 digits.

You can use PowerShell in the parameters.

The deployment notes has been updated to show examples how you can do this

Want the first 3 characters of $SerialNumber, or any other variable? (Replace the variable name and number of characters):

$($SerialNumber.Substring(0,3))

Want the last 4 characters of $SerialNumber, or any other variable? (Replace the variable name and number of characters):

$($SerialNumber.Substring($SerialNumber.Length-4))

However, as James mentions you will likely run into conflicts depending on how the vendor does their serial numbers by selecting the last X.

1 Like

This is still good to know, I had two Asus computers last week that ended up having exactly the same name because the first like 7-8 characters matched. Using the last X characters of the serials would have prevented that. Had to go back and fix it manually before it kicked the previous one off the domain lol