Creating computer object in AD
I am trying to automate/script the process of adding a Win7 SP1 computer to AD. We are running with both domain and forest functional levels at 2008 R2.
This code works to put the object in the Computer container:
ConstJOIN_DOMAIN=1
ConstACCT_CREATE=2
ConstFORCE_JOIN=32
DimoShell, sUser,sPassword,sDomain,oWMI,oCmp,sReturn
sUser="TestUser"
sPassword="password"
sDomain="mydomain"
SetoWMI=GetObject("winmgmts:\\.\root\cimv2")
ForEachoCmpinoWMI.InstancesOf("Win32_ComputerSystem")
sReturn=oCmp.JoinDomainOrWorkgroup(sDomain,sPassword,sDomain&"\"&sUser,Null,JOIN_DOMAIN+ACCT_CREATE+FORCE_JOIN)
IfsReturn<>0Then
WScript.Echo"Joindomainfailed.Error="&Err.Number&vbCrLf&"Exitingscript."
Else
WScript.Echo"Joindomainsuccessful."
EndIf
Next
But if I specify the OU to put the object in like:
sOU = "OU=laptops,OU=ejws,DC=mydomain,DC=com"
oCmp.JoinDomainOrWorkgroup(sDomain,sPassword,sDomain&"\"&sUser,sOU,JOIN_DOMAIN+ACCT_CREATE+FORCE_JOIN)
C:\Windows\debug\Net says "Cannot retry downlevel, specifying OU is not supported"
I've found some info on the net about a bug when using a domain/forest functional level of Win 2000, but nothing for 2008 R2.
May 3rd, 2012 4:44pm
I would have ask here.
http://social.technet.microsoft.com/Forums/en-US/ITCG/threads
Thanks
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2012 4:47pm
Figured it out, you have to use ";" instead of "," like this:
sOU = "OU=laptops;OU=ejws;DC=mydomain;DC=com"
May 3rd, 2012 5:00pm
The use of semicolons is described in the notes to this article describing the JoinDomainOrWorkgroup method:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa392154(v=vs.85).aspx
Richard Mueller - MVP Directory Services
Free Windows Admin Tool Kit Click here and download it now
May 3rd, 2012 7:49pm