Easy (and Automated) Computer Naming

Every client I go to has different ideas on the naming of their clients. It’s actually sometimes amazing how complicated people want it to be. If your management infrastructure is setup properly and working, for clients it shouldn’t really matter what your desktops, laptops and tablets are called. Here is a quick way to name your machines using some scripting to make it automated so you can build and forget.

What to name them?

We could discuss this for hours, but it doesn’t need to be difficult at all. In fact think of all the information you have at your finger tips that is unique to each machine that can be extracted using variables. The most common one I use a lot is %AssetTag% or %SerialNumber%. In these examples though, I am going to look at using the MAC address. We are going to use the last eight characters from the MAC address and strip out and other non alphanumeric characters to give us a valid name which we can use for the NetBIOS name of the machine.

Using MDT

The first method for this uses MDT to complete the process. I am going to build on a post I did a long time ago about using User Exit Scripts within MDT. Here is the script we will be using.

Function UserExit(sType, sWhen, sDetail, bSkip)
     UserExit = Success
End Function
Function GenerateName(vMac)
    oLogging.CreateEntry "UserExit - Compiling OSDComputerName"

    Dim objRegExp, outputStr
    Set objRegExp = New Regexp

    objRegExp.IgnoreCase = True
    objRegExp.Global = True
    objRegExp.Pattern = "[(?*"",\\<>&#~%{}+_.@:\/!;]+"
    outputStr = objRegExp.Replace(vMac, "")
    oLogging.CreateEntry "UserExit - Generated OSDComputerName" & Right(outputStr, 8)
    GenerateName = Right(outputStr, 8)
End Function

The scripting here is fairly simple, we are using a regular expression to list the characters we would like to remove from the string we pass. MAC addresses are stored with the colon as the separator so we need to strip this out. This is what the pattern is defining along with other characters just to make sure. Once we have our prepared string, it’s really easy from here to lift the eight characters from the right side. Why do we use the right and not the left.

The easy way to explain this is that on the left, the first four if you run the same manufacturer of network card or device (depending on the setup) will always be the same, this is the ID of the vendor, so it seems pointless to limit ourselves. This is why I like to use the eight characters from the right.

Setup

If you already have your MDT task sequence then this will already be setup for you. Just modify your CustomSettings.ini file to include the variable OSDComputerName and the line to instruct MDT where the script is located, save the script above into the Scripts folder of your Deployment Toolkit and you are good to go after you update your distribution points (for your toolkit package and where you keep your CustomSettings.ini). The magic will happen when the Gather task sequence step is executed and your machine will complete it’s build process with the correct name.

In my next post I will provide the same solution using PowerShell which is arguable the better way to do things these days, this will also work if you are not using MDT in your task sequences.

Advertisements

Tags: , , , ,

About Martyn

Martyn is one of the Senior Cloud Architects and DevOps Team Leader at one of the worlds leading Cloud Transformation Specialists Inframon. Martyn is responsible for the architecture of some of the largest Azure deployments in EMEA and is a advisor to a many businesses on their strategies. Martyn is a regular speaker at Microsoft events and community events on Azure and DevOps, giving his insight to a growing number of audiences.

Trackbacks / Pingbacks

  1. Even Easier (and automated) Computer Naming | All Things ConfigMgr - January 13, 2014

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: