Use the computer name in SCCM to put the client in a specific OU in active directory

From The IT Community
Jump to: navigation, search




Here is how to use the computer name in SCCM to put the client in a specific OU in active directory:


The following script will parse the computer name during OSD and set an Task Sequence variable which you can then use in the "add domain" step in your Task Sequence:


Dim strComputer, OSDComputerName, env
Dim objWMIService, objChassis, colChassis, strChassisType 
Dim OSDDomainJoinOU, strChassisTypeIs 
       Set env = CreateObject("Microsoft.SMS.TSEnvironment")
       OSDComputerName = env("OSDComputername")
If OSDComputerName="" Then 
       OSDComputerName=env("_SMSTSMachineName")
End If

'Default:	
       strChassisTypeIs = "Computers"
       OSDDomainJoinOU = "OU=Computers,OU=Test,DC=theitcommunity,DC=com"
       SubGetChassisType
       subGenLocale
       env("OSDDomainJoinOU")=OSDDomainJoinOU
WScript.Quit

Sub subGenLocale
      Select Case Mid(ucase(OSDComputerName),5,2) 
               Case "AT" 
                       If InStr(ucase(OSDComputerName),"SB") Then
'				Linz, AT
				OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=ATL,DC=theitcommunity,DC=com" 
                       End If
                       If InStr(ucase(OSDComputerName),"DI") Then
'				Vienna, AT
				OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=ATV,DC=theitcommunity,DC=com" 
                       End If
               Case "CA"
'			Waterloo, CA
                       OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=CAW,DC=theitcommunity,DC=com" 
		Case "CH"
'			Frauenfeld, CH
                       OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=CHF,DC=theitcommunity,DC=com" 
		Case "UK"
'	                Warwick, GB
                       OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=UKW,DC=theitcommunity,DC=com" 
		Case "US"
			If InStr(ucase(OSDComputerName),"NY") Then
'				New York, US
	 			OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=USY,DC=theitcommunity,DC=com" 
			End If
			If InStr(ucase(OSDComputerName),"CO") Then
'				Corona, US
	 			OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=USC,DC=theitcommunity,DC=com" 
			End If
		Case "MX"
'			Mexico City, MX
 			OSDDomainJoinOU = "OU=" & strChassisTypeIs & ",OU=MXM,DC=theitcommunity,DC=com" 
	End Select
End Sub

Sub SubGetChassisType
	If Mid(ucase(OSDComputerName),4,1) = "M" then
		strChassisTypeIs = "Notebooks"
	End If
End Sub


This is how a sample computername looks like:

ITCDUSNYxxxxxx

  • ITC=IT Community (always the same)
  • D=Desktop (change to "M" for Mobile Devices)
  • US=USA (the Country code)
  • NY=New York (the City)
  • xxxxxx=your inventory number


In your Task Sequence change "Apply Network Settings" to make it look like this:

Domainjoin.jpg



Was this article helpful? Then please donate to keep The IT Community alive...

If you found this article helpful please share it, comment and help others by writing your own article.






Translate this page:




Articles found in the same category:
(max. 20 shown)