Question : Error joining domain

When I tried to join the domain using..

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, "OU=Accounting_Computers,OU=xyz_Computers,DC=myDomain,DC=com", JOIN_DOMAIN + ACCT_CREATE)

It fails, but if I leave out the location and use...

ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, Null, JOIN_DOMAIN + ACCT_CREATE)

Then it works fine. I want the computer account to be located in Accounting_Computers, which is located inside xyz_Computers, which is located inside myDomain.com. Does anyone know why this fails when I try to specify the location?

Answer : Error joining domain

Hi, this has worked for me, using commas......

Do you have any other commas in the path that are *not* before the OU= or DC= parts?  Maybe if an OU name contains a comma then you need to escape it.

If you have, say an OU called Accounting, Main Office then maybe you need to specify Accounting/, Main Office or Accounting\, Main Office
I can't remember which way the escape character goes.....

Regards,

Rob.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
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   = "DOMAIN"
strUser     = "administrator"
strPassword = InputBox("Enter password:")
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName

'strOU = Null
strOU = "OU=IT Computers,OU=OU=Sites,DC=domain,DC=com"

Set objComputer = GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & strComputer & "'")
ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain, strPassword, strDomain & "\" & strUser, strOU, JOIN_DOMAIN + ACCT_CREATE)
If ReturnValue = 0 Then
	MsgBox "Welcome to " & strDomain & ". You must restart your system for the changes to take effect."
Else
	MsgBox "Error joining " & strDomain & ". Failed with error code " & ReturnValue
End If
Random Solutions  
 
programming4us programming4us