Dec 01, 2015 - 1 Comments - Scripting, System Center -

SCCM – Automatically put computer in OU based on it’s name during OSD

You know what saves a lot of time when imaging computers?  Having SCCM automatically put that computer in the right AD OU for you.

This system requires you to name your computers with a three letter prefix that is associated to the proper OU. No need for MDT or anything.

Set It Up

First open the properties for the All Unknown Computers Device Collection in SCCM, and add a Collection Variable called OSDComputerName with a blank value.

In your Task Sequence, add a step to run your customized version of the script below between the Apply Windows Settings and the Apply Network Settings step. (do this from a package in which there is a .bat file containing the script). In the Apply Network Setting Step, leave the Domain OU field blank.

When you run the task sequence from PXE, you will be promped to define the value of OSDComputerName. The TS will take the first three letters and move it where it needs to go. If the first three letters don’t match any in your list, it goes to the OU defined in the script as OSDDomainJoinOU. In this example script, a computer named ABC-Workstation1 will wind up in the ABC OU, whereas a computer named DEF-Workstation1 will wind up in the DEF OU, etc. Something with the first three letters that aren’t ABC, DEF, or GHI will wind up in the Workstations OU (as defined by the default).

Example Code:

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

'Default: 
 OSDDomainJoinOU = "LDAP://OU=Workstations,DC=yourdomain,DC=com"
 subGenLocale
 env("OSDDomainOUName") = OSDDomainJoinOU
WScript.Quit

Sub subGenLocale
 Select Case Mid(ucase(OSDComputerName),1,3) 
 Case "ABC" 
 OSDDomainJoinOU = "LDAP://OU=ABC,DC=yourdomain,DC=com"
 Case "DEF" 
 OSDDomainJoinOU = "LDAP://OU=DEF,DC=yourdomain,DC=com"
 Case "GHI" 
 OSDDomainJoinOU = "LDAP://OU=GHI,DC=yourdomain,DC=com"
 Case "JKL" 
 OSDDomainJoinOU = "LDAP://OU=JKL,DC=yourdomain,DC=com"

 End Select
End Sub

Next Steps?

So now that you have your computers going to the right AD OU, why not think about some intelligent deployments to device collections that are automatically populated from OU memberships?  Deploy that finance software to the finance device collection that is auto-populated from the finance OU in AD.  Then all you have to do is name a computer “FIN-whatev” and walk away while it gets built and gets the right software.

One Response to SCCM – Automatically put computer in OU based on it’s name during OSD

  1. John

    Hi there,

    I have tried but failed to make this work with a Windows 10 deployment using SCCM CB 1706.

    I have amended the text for our environment and made a *.bat for it. Then used a Run Command Line with the package and in the command line used the *bat file. However it fails.

    Could you assist any further?

    CW

    23 Oct 2017 - Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.