(SCCM 2012) OS Deployment – Prompt for computer name

So, I’ve been toying around with Mcrosoft’s System Center  Configuration Manager 2012 Beta 2, and since this has been my first exposure to this product, the experience has been somewhat interesting. Documentation and support for this Microsoft product is out there, and there are many sources that can help – so long as you search with the right terminology.
One of the challenges I was presented with, while doing an OSD (Operating System Deployment), was to prompt for a ‘custom’ computer name.
There are many easier ways of doing this, and the approach I take here is by no means the easiest one of them all.
My requirements for naming a computer account are as follows:
1. Computer name can’t be longer than 5 characters long
2. Computer name must start with an upper case letter
3. After the first initial upper case letter, computer name must have four consecutive numbers

So, due to this previous requirements, I opted for using the scripting way of prompting for a computer name while doing an OSD.
The original script was taken from this website. I contacted the author, Nicolas Moseley, and thanked him for his script, and I mentioned that I had modified his script to accommodate my needs.

The link to my modified script can be downloaded from here.

How the script works.
As the original script, the modified script will prompt the user for a computer name; however, my script will check the computer name (entered by the user or technician) against a regular expression block.

‘ Pattern will look for format – X1234 – (P = any uppercase letter, 1234 = four consecutive numbers)
‘ Global property – True or False (default False). If False, matching stops at first match
‘ IgnoreCase property – True or False (default True). If True, allows case-insensitive matching

With Regex
.Pattern = “[A-Z]\d{4}
.Global = True
.IgnoreCase = True
End With

Regex is just variable that will handle our regular expression, and the patter for the regular expression is: [A-Z]\d{4}
[A-Z] is telling the user to we’re expecting a single upper case letter from A to Z
\d{4} is telling our user that we’re expecting four decimals/numbers
Note: this is the site I read to get a better idea about regular expressions

Now, we’re going to make sure that script loops, or prompts the user, until we get the desired computer name format. This section is performed with the following Do-While loop.

‘ Let’s check that user entered new computer name in the proper format (X1234)
Do While Regex.test(sComputerName) true
‘ Keep asking for input if format is not correct
sComputerName = InputBox (“Type new computer name.” & vbCR & vbCR & “(Name format as: X1234)”, ” – Computer Deployment”, , 30,30)

This section of code will continously prompt the user for the proper format for the computer name. Notice how the Do-While loop test the regular expression pattern.
Note: Special thanks to my “dev sensei” JRod for giving the heads up about RegEx
Finally, just to make sure that things go as planned, I’m using a boolean variable (bExitCode) to identify ‘my’ exit code for the script.

Putting it all together in SCCM 2012 Beta 2
Now, we have to get this to work by creating a TS (Task Sequence) in our OSD (OS Deployment) task. Again, I chose this way, but there are other ways, so you’ll have to pick the option that best suits your needs and environment.
Run Command Line

What’s important to note is that this Run Command Line task must be set after the “Partition Disk” task and before the “Apply Operating System”. All t his information can also be found in the blog of the original author that I mentioned earlier.

That’s basically all there is to it.

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: