/build/static/layout/Breadcrumb_cap_w.png

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.

0 Comments   [ + ] Show comments

Answers (2)

Posted by: Dr. Soup 16 years ago
Senior Yellow Belt
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)
Posted by: craig16229 16 years ago
Third Degree Brown Belt
0
Dr. Soup,

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


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

Don't be a Stranger!

Sign up today to participate, stay informed, earn points and establish a reputation for yourself!

Sign up! or login

Share

 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ