Set OSDComputerName during MDT or SCCM Deployment with VBScript

This is a simple script I wrote for programatically setting the OSDComputer name during a deployment (MDT or SCCM).  It first collects several values (Make, Model, Serial, Name) then follows pre-set rules for naming conventions.  If a valid name cannot be determined, it prompts

 
 
 
 
 
(0)
1,652 times
Add to favorites
System Center
7/25/2013
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • script
    1 Posts | Last post October 28, 2014
    • *******************
      
      Dim strComputer, objWMIService, colBIOS, objBIOS, strServiceTag
      strComputer="."
      Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
      Set colBIOS = objWMIService.ExecQuery("Select SerialNumber from Win32_Bios")
      For Each objBIOS In colBIOS
      strServiceTag = objBIOS.SerialNumber
      Next
      
      Dim sNewComputerName, oTaskSequence, sTSMachineName, bPromptName
      Set oTaskSequence = CreateObject ("Microsoft.SMS.TSEnvironment")
       
      ' Get the name the computer is set to receive and truncate to first 6 letters
      sTSMachineName = lcase(oTaskSequence("_SMSTSMachineName"))
      If left(sTSMachineName,6) = "minint" Then
         bPromptName = True
      ElseIf sTSMachineName = "minwinpc" Then
         bPromptName = True
      Else
         bPromptName = False
      End If
       
      ' Note: The wscript.echo commands are logged in SMSTS.log for troubleshooting.  They are not displayed to the end user.
      If bPromptName = True Then
         wscript.echo "Detected that the computer name is scheduled to receive a random value.  Prompting user to input a standard name."
         sNewComputerName = InputBox ("Please enter your Location Code to continue." & vbCrLf & _
         "The name will be set to XXX-" & strServiceTag & vbCrLf & _
         "where XXX is the location you enter.", "Computer Location", , 30,30)
         oTaskSequence("OSDComputerName") = UCase(sNewComputerName & "-" & strServiceTag)
         wscript.echo "Set Task Sequence variable OSDComputerName to: " & sNewComputerName & "-" & strServiceTag
      Else
         wscript.echo "Computer set to receive a standard name, continuing as is."
      End If 
      ***************************************
  • Great Post
    1 Posts | Last post October 28, 2014
    • DCtheGeek, 
      I believe what you produced above is great!! I am not quite ready to use something that has all the logic you have in place. I however needed your input in modifying the script below to meet one additional requirement.
      
      My Script right now prompts me to type in a 3 digit location code and appends that to "-ServiceTag" so my PC name will be "ABC-1234567". I am happy with the way it works on physical devices. When it comes to a VM (vmware)when it queries the serial Number, I believe it pulls the MAC Address with Spaces and long name as well.
      
      I want to be able to truncate the name to max 15 characters so my TS will not error out. At this moment, I just want a solution so my TS will not error out when it gets the 15 Plus characters as the computer name.
      
      Any help will be appreciated. 
      Thank you,
      Petros
      
  • Can it work with Config manager without MDT integrated?
    2 Posts | Last post March 11, 2014
    • Hi ,
      
      Just want to check if this script can work with ocnfig manager without MDT integration? Thanks
      
      Regards,
    • MS Expert 2010,
      
      No, it has a dependency on ZTIUtility.vbs which is part of the MDT Toolkit Package.  It will not work without the MDT Extensions / Toolkit Package in ConfigMgr.  The essentials of what its doing could be done without MDT, however, but I am using several of the functions from ZTIUtility.vbs that made creating the script easier / faster.
      
      Plus, why wouldn't you want MDT Extensions in your ConfigMgr? : )
      
      /DCtheGeek