joining machines to a specific OU wth VBscript
There is a widely posted VBscript that joins a machine to a specific Active Directory Organization Unit (as opposed to the default OU), but I cannot get it to fully work.
The script (along with a few small edits for my environment that are xx'ed out) is as follows:
- - - - - -
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "xxxxxxxx"
strPassword = "xxxxxxxx"
strUser = "xxxxxxxx"
strOU = "OU=xxxxxxxx,DC=xxxxxxxx,DC=xxxxxxxx,DC=xxxxxxxx"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = _
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _
& strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
- - - - - -
Problem: In testing, a machine successfully joins the domain, but continues to be dumped into the default, built-in "Computers" OU instead of my preferred OU.
I have used ADSI to make sure I am using the fully qualified RFC 1779 DN of my OU for my "strOU", and I have made sure that my "strUser" account has the permissions to create computer accounts in that OU.
Any ideas what I am missing?
TIA,
Craig
post script: My apologies if I should have posted this in the "scripting" forum. My goal is to have this script run at the time of imaging, and that is where my head was at.
The script (along with a few small edits for my environment that are xx'ed out) is as follows:
- - - - - -
Const JOIN_DOMAIN = 1
Const ACCT_CREATE = 2
Const ACCT_DELETE = 4
Const WIN9X_UPGRADE = 16
Const DOMAIN_JOIN_IF_JOINED = 32
Const JOIN_UNSECURE = 64
Const MACHINE_PASSWORD_PASSED = 128
Const DEFERRED_SPN_SET = 256
Const INSTALL_INVOCATION = 262144
strDomain = "xxxxxxxx"
strPassword = "xxxxxxxx"
strUser = "xxxxxxxx"
strOU = "OU=xxxxxxxx,DC=xxxxxxxx,DC=xxxxxxxx,DC=xxxxxxxx"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer = _
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" _
& strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
NULL, _
JOIN_DOMAIN + ACCT_CREATE)
- - - - - -
Problem: In testing, a machine successfully joins the domain, but continues to be dumped into the default, built-in "Computers" OU instead of my preferred OU.
I have used ADSI to make sure I am using the fully qualified RFC 1779 DN of my OU for my "strOU", and I have made sure that my "strUser" account has the permissions to create computer accounts in that OU.
Any ideas what I am missing?
TIA,
Craig
post script: My apologies if I should have posted this in the "scripting" forum. My goal is to have this script run at the time of imaging, and that is where my head was at.
0 Comments
[ + ] Show comments
Answers (2)
Please log in to answer
Posted by:
Dr. Soup
15 years ago
You never actually use the "strOU" variable you set up.
Replace the "NULL" argument from JoinDomainOrWorkGroup with the OU you want so it looks something like this:
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
strOU, _
JOIN_DOMAIN + ACCT_CREATE)
Replace the "NULL" argument from JoinDomainOrWorkGroup with the OU you want so it looks something like this:
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, _
strPassword, _
strDomain & "\" & strUser, _
strOU, _
JOIN_DOMAIN + ACCT_CREATE)
Posted by:
craig16229
15 years ago
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.