Friday, June 22, 2012

SCCM: Name Computer Prompt during OSD

There are a few ways to stage a computer for SCCM OSD.  I will show how I set the computer name during the SCCM OSD without having to prestage the computer in SCCM.  This tip is generally used when your operating system deployments are on site and the IT personnel is going to be in front of the machine.  This may not work as well in a remote deployment scenario as it requires user interaction on the client end and therefor is not considered a zero touch solution. 

1) First we need to create a VBScript which will create an input box and capture the computer name we enter during the OSD.  I have modified the script below (original script author unknown) and added some logic to it that I will explain. 

The script sets some variable and defines what characters are allowed to be in a computer name.  Remember that a computer name can only include the characters a-z, A-Z, 0-9, or a dash.  Next it pops up the input box with instructions and converts the name you enter to uppercase.  If the computer name is longer then 15 characters then SCCM with through a generic error later down the line. Here we verify the name length before moving on.  Next we verify that the computer name contains only valid characters.  If any of these checks are false then the field goes blank and you need to enter a new computer name.  Last, the computer name is saved as a variable OSDComputerName.  This is variable that Microsoft has programed SCCM to check for during a later Task Sequence (I could not find which one but it could be Windows Settings or Setup Windows).  Copy the below script into a text file and name the file SetComputerName.vbs

Note: If you leave the input field blank and click OK and are doing a computer refresh then the original computer name should be used if you also have the Task Sequence capture Windows Setting (This needs to be tested).


Dim objOSD, objRegEx
Dim Matches, Match
Dim strPattern, strInputBox, strReason
Dim boolLength, boolValid

Set objOSD = CreateObject("Microsoft.SMS.TSEnvironment")
Set objRegEx = New RegExp

' Define valid patterns as and character not in (A-Z, 0-9, or -)
strPattern = "[^a-zA-Z0-9-]"

 strReason = ""
 strInputBoxA = InputBox("Enter desired machine name:" & VbCrLf & VbCrLf & "Names must be less then 16 characters, and only include A-Z, 0-9, or -.","Machine Name",,60,60)
 If strInputBoxA = "" Then TemplateQuit(0)
 strInputBox = UCase(strInputBoxA)

 ' Check length - must be less than 16 charatcers
 If Len(strInputBox) <= 15 Then
  boolLength = True
  boolLength = False
 End If
 ' Check character validity
 boolValid = True
 ' Return all matches for invalid characters
 objRegEx.Global = True
 objRegEx.Pattern = strPattern
 ' Generate collection of matches
 Set Matches = objRegEx.Execute(strInputBox)
 ' Check for matches on invalid characters
 For Each Match In Matches
  boolValid = False
Loop While Not (boolLength And boolValid)

objOSD("OSDComputerName") = strInputBox


2) Create an SCCM package that contains only the VBScript we just created.  One of the first Task Sequences should be this Run Command Line with a setup similar to the below screen capture.

     "%SYSTEMROOT%\System32\cscript.exe" ".\SetComputerName.vbs"

1 comment:

  1. hey Bro,
    you save my day..
    can you tell me how to do User stat migration..bcoz there is no clear picture on internet for this..both online and offline mode.