Update 10-31-14: This will also work with MDT 2013 as I have tested it.

I have been focusing on Windows deployment lately and have been working on upgrading my servers to MDT 2012. While updating some of my windows image I wasn’t too happy with the naming convention that  we are currently using in my enterprise as it is not helpful for identifying machines. I decided to create an MDT form that will generate a computer name based on a series of question that are relevant to my environment. In this article I will go through the process of how you can accomplish creating a custom MDT 2012 computer name form for your environment.

  1. Let’s start by first creating the layout for our custom form. MDT forms are HTML based and you can use any online HTML editor to help you with the creation of your form. The editor that I like to use is the one located here.

Let’s start by creating a simple drop down box that allows you to select different operating systems.

<table style="width: 100%;">
<tr>
<td style="width: 160px;"><span class=Larger>Operating System:</span></td>
<td align="left">
<select name="OperatingSystem" class=WideEdit" language=vbscript onpropertychange=generateComputerName >
<option value="A">W7x64</option>
<option value="B">W8x64</option>
<option value="H">W2K8-R2 Server</option>
<option value="I">W2K12 Server</option>
<option value="M">MAC</option>
<option value="L">LINUX</option>
<option value="O">Other</option>
</select>
</td>
</tr>
</table>

The results of the above code is the following:

Drow-Down

Each operating system is assigned a different value and this value is then used for the computer name. You can have multiple drop downs with different options in the MDT form. It all depends on the naming convention that you use in your environment. You can modify the attributes above and change them to suit your needs. They should be self-explanatory and if you are having trouble you can always look at the definition of each one to understand how they work. Note that “onpropertychange=generateComputerName” is a function in a VBScript that I am calling. You will see later on what this function is doing.

Let’s go ahead and see how a text box is created.

<table style="width: 100%;">
<tr>
<td style="width: 160px;"><span class=Larger>Room Number:</span></td>
<td align="left">
<input type=text id="RoomNumber" name=RoomNumber size="4" maxlength="4" language=vbscript onpropertychange=ValidateRoomNumber  />
<label class=ErrMsg for=RoomNumber>* Required</label>
<label class=ErrMsg id=InvalidChar>Invalid characters! Make sure it is all caps.</label>
<label class=ErrMsg id=BadLength>Must be exactly 4 characters!</label>
</td>
</tr>
</table>

Text-Box

The above HTML code produces a text box that allows the user to input a room number. Room number is another option that I use when generating my computer names.  The room number is restricted to be 4 alphanumeric digits and calls a function “ValidateRoomNumber” in my VBScript that takes care of validating that it is a correct room number. Later on you will see how this function works and how the error messages get displayed if the value that they enter is incorrect. The “ErrMsg” class in the code above will only appear if the room number is incorrect. I have three different type of errors that I am covering for room numbers but you can have more or less depending on the content and constraints that you want to enforce.

The last thing that I want to cover is how to display a simple text message in your form.

<p>Note: Message goes here</p>

The above should be self-explanatory but all that you are doing is enclosing the text in “P” tags.

With the above code you should be able to create a form for your environment that suits your needs. My complete form in MDT 2012 looks like the following:

Sample-MDT-Form

You can download the sample form here and replace my code with yours so that it fits the need of your environment. You should replace the code between the following tags:

<![CDATA[
Your HTML code goes here.
]]>

Everything else in the form you will need but you can modify some of the names and change them to whatever you like. Note that at the top of the file I am referencing my VBScript which we will talk about next.

2. The VBScript that ties to the form above does validation of the different fields and generates the computer name. In the picture above, you can see a text box at the bottom that holds the complete generated computer name. The VBScript has a function that takes care of this generation. Below is one of the functions that I am using for validation:

	Function ValidateRoomNumber
	
	   ' Check Warnings
	   ParseAllWarningLabels
	
	   If Len(RoomNumber.value) <> 4 then
	      InvalidChar.style.display = "none"
	      BadLength.style.display = "inline"
	      ValidateRoomNumber = false
	      ButtonNext.disabled = true
	   ElseIf IsValidRoomNumber ( RoomNumber.Value ) then
	      ValidateRoomNumber = TRUE
	      InvalidChar.style.display = "none"
	      BadLength.style.display = "none"
	      
	      generateComputerName()
	      
	   Else
	      InvalidChar.style.display = "inline"
	      BadLength.style.display = "none"
	      ValidateRoomNumber = false
	      ButtonNext.disabled = true
	   End if
	
	End function

The above function validates the room number in the computer name form and you can see me calling it by using the “onpropertychange=ValidateRoomNumber” attribute. The first thing that it is doing is verifying that the length is equal to 4. If it does not equal 4 then it will display the message with the “ID=BadLegth” and disable the next button in the form. If the value of room number is equal to 4 then we make sure that it is a valid room number by calling the function “isValidRoomNumber(Parameter1)” with the value of the room number as the parameter. The isValidRoomNumber(parameter1) function is below:

	FunctionIsValidRoomNumber(RoomNumber)

	 const IVNAME_TEST="[A-Z0-9]{4}"
	 DimregEx, match, myMatches

	 SetregEx=New RegExp
	 regEx.Pattern=IVNAME_TEST
	 regex.IgnoreCase=false

	 SetmyMatches=regEx.Execute(RoomNumber)
	 IfmyMatches.Count>0Then
	   IsValidRoomNumber=true
	 EndIf

	Endfunction

In this function, I am creating an initialization vector with a regular expression as its value. My regular expression allows only capital letters, the numbers 0 through 9, and it has to be 4 characters only. Following the initialization vector creation are some declarations and I am also making sure that it does not ignore cases when we do comparisons. I then test the regular expression against the Room Number that was passed in to the function and see if there are any matches. If there is a match then the count is greater than 0 which means that it is a valid room number and the function returns as true.

Going back to the ValidateRoomNumber function, the last case deals with the room number being invalid. If the room number is invalid then we display the message with the “ID=InvalidChar”. The other functions in this VBScript should be self-explanatory after reading the above explanations so I will skip those. Instead, I will analyze the last function in the VBScript that handles the computer name generation.

	FunctiongenerateComputerName

	 oEnvironment.Item("OSDComputerName") = OperatingSystem.Value & UserLocation.Value & RoomNumber.Value & DeviceType.Value & "-" & Identifier.Value & ComputerNumber.Value
	 SBComputerName.Value = OperatingSystem.Value & UserLocation.Value & RoomNumber.Value & DeviceType.Value & "-" & Identifier.Value & ComputerNumber.Value

	EndFunction

In the function above, I am assigning my computer name to two different variables. One is called oEnvironment.Item(“OSDComputerName”) and this variable is what MDT uses to name your computer after deployment. The other variable which is called SBComputerName.Value is the text box at the bottom of my form that holds the complete computer name:

Sample-Computer-Name-Box

You can download the sample VBScript file here and modify it for your purpose.

  1. Now that you have both of your forms completed, you want to go ahead and save them over to your MDT Share directory under the “Scripts” folder. While you are here, you also want to modify the following two MDT files so that your forms will display during the operating system deployment.

a. In the DeployWiz_Definition_ENU.xml file you want to add the following lines:

		<Pane id="SBComputerName" reference="DeployWiz_SBComputerName.xml">
		   <Condition><![CDATA[UCase(Property("SkipDomainMembership"))<>"YES" or UCase(Property("SkipComputerName"))<>"YES"]]></Condition>
		   <Condition><![CDATA[Property("DeploymentType")<>"REPLACE" and Property("DeploymentType")<>"CUSTOM" and Property("DeploymentType") <> "StateRestore" ]]></Condition>
		</Pane>

Make sure to change the reference="DeployWiz_SBComputerName.xml” above to point to the name of your .xml file. Also, when adding these lines in the DeployWiz_Definition_ENU.xml file insert them before the

“<Pane id=”ComputerName” reference=”DeployWiz_ComputerName.xml”>”

section. This will tell MDT to display your custom form as part of the task sequence.

b. The other file that we want to modify is the “DeployWiz_ComputerName.xml”. This is the default MDT file that takes cares of letting users type in a computer name. Since we have our own naming form that will generate a computer name then we must modify this file and disable the field where users normally type the computer name.

		<input type=text id="OSDComputerName" name=OSDComputerName size=15 disabled=true language=vbscript onpropertychange=ValidateComputerName AccessKey=t/>

Note in the above line the “disabled=true” attribute that I added to disable it.

This should cover the entire process for creating a custom computer name form for MDT. You can optimize some of the code in the VBScript above but the efficiency gains will be small and won’t matter in this case. Thank you for taking your time to read this article.

17 Responses to “MDT 2012/2013 Custom Computer Name Form”

  1. This post is very very informative.
    Suppose, I wanted to automatically populate the computer name with a country code and serial number>?
    I understand the serial number portion but unable to figure out how to incorporate a drop down list of the two letter country code for our techs to choose from! Can you assist me?

    • Kevin,

      This should be pretty simple. See the code below for a quick way to do it.

      Country Code:

      Note that this will also work with MDT 2013 as I am currently using the custom form there as well. Look at the example form here:

      https://docs.google.com/file/d/0B5eN5sBSX2zLcWpsYTU1TzdOczg/edit

      as it pretty much does what you are asking. Additionally, you can copy and paste the code from above or from the file into here:

      http://www.w3schools.com/html/tryit.asp?filename=tryhtml_intro

      to see a preview. Let me know if you have any other questions

      • Tieku Bortei-Doku says:

        How do I include the serial number using the %SerialNumber% variable?

        • Nick Jessup says:

          Any update on this?

          • Yeah see my comment posted to the question above.

          • Tieku Bortei-Doku says:

            I notice you have validation for the text input fields but not the dropdown fields. Have you thought of a way of doing this and also having ButtonNext.disabled = true when it’s only dropdown choices.

          • That should be doable if you want to do validation on the drop downs to make sure that they are not left blank before moving onto the next form. I would give you the code to do so but my test environment is currently down and won’t be up for another few weeks. There are plenty of examples online that you can use as a reference.

            Regards,

            Glenn

        • You should be able to query the serial number via WMI using the following in the VBScript above:

          strComputer = “.”
          Set objWMIService = GetObject(“winmgmts:” & “{impersonationLevel=impersonate}!\\” & strComputer & “\root\cimv2”)
          Set colSMBIOS = objWMIService.ExecQuery(“Select * from Win32_BIOS”)

          For Each objSMBIOS in colSMBIOS
          strSerialNum = objSMBIOS.SerialNumber
          Next

          The variable strSerialNum should contain the serial number. Also, the following might retrieve the serial number as well but I haven’t had a chance to test it:

          oEnvironment.Item(“SerialNumber”)

          Regards,

          Glenn

          • Tieku Bortei-Doku says:

            Yes I was able to get it to work with something like this:

            Dim SerialNumber

            SerialNumber = oEnvironment.Item(“SerialNumber”)

            oEnvironment.Item(“OSDComputerName”) = ComputerLocation.Value & SerialNumber
            SBComputerName.Value = ComputerLocation.Value & SerialNumber

            Thanks

    • Kevin,

      My apologies, it looks like the comment actually rendered the HTML code rather than displaying it in raw form. See here:

      https://drive.google.com/file/d/0B5eN5sBSX2zLbWtfdlhRdV9LNmM/view?usp=sharing

      for the actual code. Let me know if you have any other questions.

  2. Could you clarify this part for me pls

    Make sure to change the reference to point to your .xml file and also add these lines before the “” in the DeployWiz_Definition_ENU.xml file. This will tell MDT to display your custom form as part of the task sequence.

    • My apologies, I have fixed the portion in article above. Let me know if it is still not clear enough so that I can upload the files and insert pictures.

      • I had to modify your original line for the DeployWiz_Definition_ENU.xml file to include “”

        <![CDATA[UCase(Property("SkipDomainMembership"))”YES” or UCase(Property(“SkipComputerName”))”YES”]]>
        <![CDATA[Property("DeploymentType")”REPLACE” and Property(“DeploymentType”)”CUSTOM” and Property(“DeploymentType”) “StateRestore” ]]>

        Its all working now I just need to modify it as I don’t need all the selection options so I may come back to you for a little help with that. Also why not just hide the original “ComputerName” pane in your custom.ini file.

        • Glenn, hang on I have just seen the problem when leaving a reply It removes parts of the reply namely the start and end Condition tags that are required for it to work.

        • Yup, you are right. The condition tags got removed from the post. I will post a screen shot of the code instead so that it is more clear.

          The reason why I do not hide the original “ComputerName” Pane is because if you look at the XML file that it references “DeployWiz_ComputerName.xml” then you will notice that this file also has fields for joining the computer to a domain or workgroup which most people will use. In a task sequence this is called the “Computer Details” section. See the screenshot:

          https://flic.kr/p/rprB4W

  3. Hello Glenn,

    I have a question you might be able to help me with, I want to use a custom pane to set locale settings. As in. If I select UK it will set the locale settings in MDT to those for the UK. Can I somehow use this for that? or can you please help me in the right direction?

    Please guide me 🙁
    Greetings from another fellow called Glenn 😉

Leave a Reply

Your email address will not be published. Required fields are marked *