Setting the Computer Name
The PC will automatically generate a computer name, but if you'd like to set your own standard, you will need to set the variable COMPUTERNAME before the Apply OS Step while in the WinPE stage or leverage the Rename-Computer function while in the Full OS.
Using PowerShell:
See a simple example Set Computer Name with Script. Basically it comes down to setting this task sequence variable to what you want the computer to be named.
${TSEnv:ComputerName} = CUSTOMNAME #15 Char or lessUsing Set variable step
You can also use a Set variable to simply set the name, in this example I'm naming the computer "DC", which is typically a horrible name, but this task sequence is for creating my Lab's Domain Controller, so it actually makes sense for this. However, using a "Set variable" step typically is a bad way to do it, as it will set the name to this each time, all the more reason to script your process to build the name you want based on serial, asset tag, etc.

You will notice that the variable is set before the "Apply Windows... " step so that the task sequence will consume that variable and apply it to the unattended file.
PowerShell Function Rename-Computer in Full OS
Leveraging the built in PowerShell function "Rename-Computer" once in the full OS, it is also possible to set the computer name. I do this for Hyper-V lab machines to automatically grab the Hyper-V VM name and use that for the device. See example below.
Offline Domain Join
If you're doing offline domain join, just make sure you've set the COMPUTERNAME variable before the Offline Domain Join step, or it will default to the standard set in that step, which is serial number. If you have pre-set the COMPUTERNAME variable, the Offline domain join step will honor that variable and not change it to the %SERIALNUMBER% variable. Note that if your Serial Number is logner than 15 characters, it will break the process, so recommend doing something like PC-%SERIALNUMBER:12% so it will set a prefix of PC- and then only grab 12 characters of the Serial Number.
Computers that are members of an Active Directory domain can't have names that contain only numerals. This is a DNS restriction. For More information: https://learn.microsoft.com/en-us/troubleshoot/windows-server/active-directory/naming-conventions-for-computer-domain-site-ou

Last updated

