Share via


SCCM 2012: How to Customize Computer Name, Domain Joining and Moving to Right OU During OSD

There are numerous articles published for Customizing Computer Name, Domain Joining and Moving to Right OU during OSD. However, they imply an idealistic environment. But all environments are not Ideal and they have their own challenges. Below were the challenges in a client environment and they needed SCCM 2012  to work flawlessly to fulfill their needs.

  • They do not want to Integrate MDT due to some internal political reason
  • They don't want their computer name to include Serial No or Asset Tag. They want users Unique User ID to be in computer name
  • Computer name should indicate Location, Device Type (Laptop or Desktop)
  • Depending on Device Type (Laptop or Desktop) system should be moved to right OU
  • Depending on computer name system should be joined to right Domain
  • They wanted to keep it simple and technician friendly
  • And above all it should be in a single task sequence

Here is what we ended up with to fulfill all above needs:

  1. Task sequence
  2. Use VBscript for technician to prompt for Location and User ID. Technician enters location (3 letters based on defined by organization), determine if it is Laptop or Desktop from BIOS and record as CL or CD. Technician enters UserID.

Eg ABCCL-USERID for Laptop and ABCCD-USERID

Variables are set and it will be used while assigning OSDComputername during Task sequence

Note : Use the script Before Running Apply Operating System Step!

'start script
Dim strlocation
Dim strSerialNum
Dim strDevice
Dim strComputerName
Dim strLclUser
Dim strLclPW
Dim strComputer
Dim objWMIService
Dim objComputer
  
' Set Variables
SET env = CreateObject("Microsoft.SMS.TSEnvironment")
strLclUser = "Administrator"
strLclPW = "TypePassword f Local admin"
  
'Set wshShell1 = CreateObject("WScript.Shell")
'strlocation = left(WScript.ScriptName,(len(WScript.ScriptName)-4))
  
'Prompt For Location
strlocation = INPUTBOX("Enter Location Name")
  
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colChassis = objWMIService.ExecQuery _
 ("Select * from Win32_SystemEnclosure")
For Each objChassis in colChassis
 For Each strChassisType in objChassis.ChassisTypes
 Strdevicevar = strChassisType
 Next
Next
  
If StrDEvicevar = 3 then
strdevice = "CD"
else
Strdevice = "CL"
end If
  
'Prompt For UserID
strUserID = INPUTBOX("Enter UserID")
  
' Set Computer Name
strComputerName = strLocation & strDevice & "-" & strUserID
  
'Set OSD Computer Name Variable
env("OSDComputerName") = strComputerName
  
'End Script

 

Setup Domain Variable Logic: Script It checks if computer name starts with ABC then it will have to be added to XYZ.local domain and if it starts with DEF it will add to UVY.local domain. You can add as many as locations and domains in the script. Make sure you are ending the If statement and after you create one:

eg  ** If** threeChars = "LMN" Then

 sBuiltDomain = "QRS.local"

  ** End If**

'start script
set env = CreateObject("Microsoft.SMS.TSEnvironment")
 sComputerName = env("OSDComputerName")
 threeChars = UCase(Left(sComputerName,3))
 sBuiltDomain = "NOT_set!"
 If threeChars = "ABC"  Then
 sBuiltDomain = "XYZ.local"
  End If
 If  threeChars = "DEF"  Then
 sBuiltDomain =  "UVY.local"
  End If
  
 env("OSDDomainName") = sBuiltDomain
 Wscript.quit
'end script

 

Add the Script after Apply Windows Settings step:

 

 

 Setup OU Variable logic : Script checks if Computer name if it has CL(Laptop) or CD(Desktop) and moved it to correct OU. You can add as many as locations and domains in the script. Make sure you are ending the If statement and after you create one:

 

'Start script
set env = CreateObject("Microsoft.SMS.TSEnvironment")
 sComputerName = env("OSDComputerName")
 fiveChars = UCase(Left(sComputerName,5))
 sBuiltOU = "NOT_set!"
 If fiveChars = "ABCCL"  Then
 sBuiltOU = "LDAP://OU=Windows 7,OU=Laptops,DC=ABC,DC=local"
  End If
 If  fiveChars = "ABCCD"  Then
 sBuiltOU =  "LDAP://OU=Windows 7,OU=Desktops,DC=ABC,DC=local"
  End If
 If fiveChars = "DEFCL"  Then
 sBuiltOU = "LDAP://OU=Windows 7,OU=Laptops,DC=UVY,DC=local"
  End If
 
 If fiveChars = "DEFCD"  Then
 sBuiltOU = "LDAP://OU=Windows 7,OU=Computers,DC=UVY,DC=us,DC=local"
  End If
  
 env("OSDDomainOUName") = sBuiltOU
 Wscript.quit
'end script

Apply Network Settings: make sure you use correct account to run this step and it should have access in AD to join system and move it to correct OU.

Credits

Thanks to Romano Jerez for the MoveOU script where the logic is taken from and which is modified according to my requirement:

http://blog-en.netvnext.com/2012/02/osd-automate-domain-ou-name-from.html#!/2012/02/osd-automate-domain-ou-name-from.html