Skip to content

Instantly share code, notes, and snippets.

@brent20
Created April 21, 2015 14:50
Show Gist options
  • Save brent20/a9d1cd7e3c40db544fba to your computer and use it in GitHub Desktop.
Save brent20/a9d1cd7e3c40db544fba to your computer and use it in GitHub Desktop.
' ** Configure the Target OU here
strLDAPofOU="OU=TargetOU,OU=Workstations,OU=AnotherLevel,OU=Root,DC=MyDomain,DC=com"
On Error Resume Next
'Get MachineObjectOU Value
Set wshNetwork = CreateObject("WScript.Network")
Set oFso = CreateObject("Scripting.FileSystemObject")
Set objSysInfo = CreateObject( "ADSystemInfo" )
Set ArgObj = WScript.Arguments
'Use the variable as the target OU
strMachineObjectOU = strLDAPofOU
strComputerDN = objSysInfo.ComputerName
'msgbox(strMachineObjectOU)
nComma = InStr(strComputerDN,",")
strCurrentOU = Mid(strComputerDN,nComma+1)
strComputerName = Left(strComputerDN,nComma - 1)
'msgbox(strCurrentOU)
'If current OU is different than target OU then move computer to target OU
If UCase(strCurrentOU) <> UCase(strMachineObjectOU) Then
Set objNewOU = GetObject("LDAP://" & strMachineObjectOU)
Set objMoveComputer = objNewOU.MoveHere("LDAP://" & strComputerDN, strComputerName)
'msgbox("LDAP://" & strComputerDN & strComputerName)
End If
'// End Script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment