Created
April 21, 2015 14:50
-
-
Save brent20/a9d1cd7e3c40db544fba to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
' ** 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