Graeme Bray

Real World Automation and Deployment

Capitalize MDT Computer Name (no matter how it was entered)

leave a comment »

In an enterprise environment, the most important thing is a consistent environment, whether it be something with multiple components such as IIS, or something as simple as a Computer Name case. Without any type of consistency, how can you support any environment? I think I’ve eluded to this on a couple of my other posts. Consistency is a big thing in our environment.

We were recently approached by our monitoring team stating that Server systems were being built with either a lowercase name (ex: testserver01) or uppercase name (ex: TESTSERVER02). They were trying to get the inconsistency fixed, which is completely understandable.

I was tasked with finding a solution to the problem. I thought, this should be pretty simple. There is a Task Sequence variable called OSDComputerName that I should be able to use the built-in functions to perform a UCase on via VBScript. I created a script (which I lost, due to some automated copy methods I have in place. Oops.

I tried to use the script in my Preinstall phase of my test Task Sequence (GEB_test in this case). I put it after the Configure step. I was able to get the OSDComputerName to show that it was properly being capitalized, but when I went into the OS, it showed a lowercase name still. I gave up for a few days, knowing that when you keep looking into a problem, a solution never presents itself. I came back to my issue today after setting my tasks of things to do, which included this issue.

After getting frustrated that my initial solution, and subsequent re-tries never worked, sent a message to Mikael Nystrom and Johan Arwidmark. I got a couple responses, including one from Tim Mintner, Mikael asked that I follow up via e-mail, which I was working on before the end of the day. I had a quarter of the e-mail typed up, but realized that I lost my ZTIComputerName.wsf script. Crap. I clicked .

I got home and re-wrote my script. It took about 15 minutes in total, as I borrowed some other template code I had and removed 95% of it, which, if you aren’t doing, you’re doing it wrong. Andrew Barnes has a great template (or you can edit and re-use some of Johan’s or Mikaels, if you’ve bought their books.)

After having time to have thought about my issue, I found the simplest solution after some simple thinking.
I was changing the computer name too *late* in the Task Sequence.

First, I created my script, as seen below

<job id="ZTIComputerName">
<script language="VBScript" src="ZTIUtility.vbs"/>
<script language="VBScript">

'//—————————————————————————-
'// Solution: Capitalize Computer Name
'//
'// Usage: cscript ZTIComputerName.wsf[/debug:true]
'// Version: 1.0 – 05-Aug-2014 - Graeme Bray
'//
'// This script is provided "AS IS" with no warranties, confers no rights and 
'// is not supported by the authors
'//
'//—————————————————————————-

'//—————————————————————————-
'// Global constant and variable declarations
'//—————————————————————————-

Option Explicit

Dim iRetVal

'//—————————————————————————-
'// End declarations
'//—————————————————————————-

'//—————————————————————————-
'// Main routine
'//—————————————————————————-

'On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0

'//—————————————————————————
'//
'// Function: ZTIProcess()
'//
'// Input: None
'// 
'// Return: Success – 0
'// Failure – non-zero
'//
'// Purpose: Perform main ZTI processing
'// 
'//—————————————————————————
Function ZTIProcess()

    Dim strComputerName
    iRetVal = Success 
    ZTIProcess = iRetval
    
    strComputerName = oEnvironment.Item("OSDComputerName")
    
    oLogging.CreateEntry "———————————————-", LogTypeInfo
    oLogging.CreateEntry "Config-ComputerName   ", LogTypeInfo
    oLogging.CreateEntry "Config-ComputerName – Current name is:       " & strComputerName, LogTypeInfo
    
	oLogging.CreateEntry "Config-ComputerName - Changing computer name to uppercase", LogTypeInfo
	strComputerName = UCase(oEnvironment.Item("OSDComputerName"))

	oEnvironment.Item("OSDComputerName") = UCase(strComputerName)
	
    oLogging.CreateEntry "Config-ComputerName - New Name - " & strComputerName, LogTypeInfo
	oLogging.CreateEntry "Config-ComputerName - Computer Name Change Complete", LogTypeInfo
	oLogging.CreateEntry "———————————————-", LogTypeInfo

End Function 
</script>
</job>

This script was saved to the D:\DeploymentShare\Scripts\ folder.

I then added it to my Task Sequence *above* the Gather local only step in my Preinstall phase.
Task Sequence

To test my script, I launched a simple 2012 R2 Task Sequence (the OS deploys in about 5 minutes and with no State Restore options, its complete in about 8 minutes. My test computer name had some upper and some lower case in it.
Computer Name - Upper/Lower Case

I hit ‘Go’ and the build completed. I checked properties of ‘My PC’ and….
Computer Name - Final

This worked out great and will soon be implemented in our environment, adding to even more consistency, even between different Engineers.

Until next time (which hopefully won’t be months in between)

Advertisements

Written by Graeme

August 6, 2014 at 2:35 AM

Posted in MDT

Tagged with

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: