I’ve updated this post on 1 April 2012 as the screenshots shows the gather as being the first step when in fact the gather has to run after the computername has been set so that it can collect the data. Sorry for that readers.
I’ve come across this issue a few times now so it’s time to post it as a blog. The scenario is that your company wants to automate computer name generation using serial numbers and indicators that show the machine type and location. The end result is that computer names are automatically created during deployments like in these examples:
Birmingham Server computername: B-S-12345
Edinburgh Virtual Machine computername: E-V-12345
Manchester Laptop computername: M-L-12345
London Desktop computername: L-D-12345
One solution to this is to use task sequence conditions in combination with the read only MDT variables DefaultGateway, IsVM, IsLaptop, IsDesktop and IsServer.
First, create a folder as a container for the various choices and call it Set Computername. Next, create more folders in a tree structure listing each of your site locations. Birmingham, Edinburgh, London and Manchester in my examples.
Click on the first site(Birmingham), then on the Options tab, select add If Statement.
Select Any Conditions and click OK.
Next, add a task sequence variable.
Enter the variable DefaultGateway and use the equals operator and the value of the first sites routers IP address (Default Gateway). 172.16.0.1 in my example.
Repeat this step for any other default gateways on the site. The result should look like this:
Do the same for the remaining sites. This will now detect the site based on the default gateways above.
Next, it’s time to create the optional computer name steps. First, highlight the first site and select General then click Set Task Sequence Variable.
This folder is Birmingham and we want it to target a laptop so under name type Computername Laptop then enter the variable OSDComputername with the value B-L-%SerialNumber%.
Do the same for Desktop, Server and Virtual Machine following the same logic.
Finally, create task sequence conditions for each step as in the examples below:
This process can be repeated for the remaining sites in the organisation. The result is that the computer names are now generated automatically.