OSD: Move Computers in AD Auto Magically

less than 1 minute read

Here is a script I wrote to put computers into different OUs based on the computer name.

On Error Resume Next
 
Set OSDenv = CreateObject("Microsoft.SMS.TSEnvironment")
 
SetOuByCompName "Test","LDAP://OU=TestOSD,DC=EphingDomain,DC=org"
 
Function SetOUByCompName (strNameStartsWith, strOU)
    strCompName = OSDenv("OSDComputerName")
	If Instr(1, strCompName, strNameStartsWith, 1) = 1 Then OSDenv("OSDDomainOUName") = strOU
End Function

In this script, if the computer’s name starts with Test in OSD, it will change the OU this computer goes in to to LDAP://OU=TestOSD,DC=EphingDomain,DC=org

You can add as many matches you want by creating more of these lines:

SetOuByCompName "Test","LDAP://OU=TestOSD,DC=EphingDomain,DC=org"

In order to set this up in ConfigMgr, create a Package with no program that has a folder with the script in it as the source folder, like this:

image7 (1)

And then create a new “Run Command Line” step in your task sequence, sometime after the partition disk step, but before the Apply Network Settings step. Configure it to look like this:

image8 (1)

Now you’re all set! If you change the script, make sure you update the content on the package so your DPs and task sequences get the change!

Categories:

Updated:

Leave a Comment