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.
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Community Chosen Answer

2
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)
Answered 12/16/2008 by: Dr. Soup
Senior Yellow Belt

Please log in to comment
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Dr. Soup,

Bingo - so simple it should have been staring me in the face. Thanks very much.


Craig
Answered 12/18/2008 by: craig16229
Third Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity