Join a PC to the domain completely via VBScript with ADSI
From: EAGroff (eric.groff_at_memphisgroffs.com)
Date: 03/01/05
- Next message: Mark Whidby: "IP address script - takes too long"
- Previous message: mayayana: "Re: changing msgbox buttons"
- Next in thread: Steve Seguis [MVP]: "Re: Join a PC to the domain completely via VBScript with ADSI"
- Reply: Steve Seguis [MVP]: "Re: Join a PC to the domain completely via VBScript with ADSI"
- Messages sorted by: [ date ] [ thread ]
Date: 1 Mar 2005 14:46:21 -0800
I have been beating my head against the wall trying to get this script
working. I am trying to join a PC to the domain and have the machine
account in the proper OU based on machine name. I keep getting 80005000
errors when it gets tot he oRoot line. has anyone had any luck with
this?
'Script for joining a branch PC to the domain and placing it in the
proper OU
'
' For WinXP and above only!
' Author: Eric A. Groff
' Date: 02/23/2005 11:11
'On Error Resume Next
Dim oRoot, oOU, strContainer
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
Const ADS_SECURE_AUTHENTICATION = &H1
Const ADS_USE_ENCRYPTION = &H2
Const ADS_USE_SSL = &H2
Const ADS_READONLY_SERVER = &H4
Const ADS_PROMPT_CREDENTIALS = &H8
Const ADS_NO_AUTHENTICATION = &H10
Const ADS_FAST_BIND = &H20
Const ADS_USE_SIGNING = &H40
Const ADS_USE_SEALING = &H80
strDomain = GetResponse(" Domain Name", "Domain", "Domain")
strUser = GetResponse(" User ID", "administrator", "JQUser")
strPassword = GetResponse(" Password", "", "passwordhere")
strTMOU =
"LDAP://OU=WAN-Linked,OU=Computers,OU=Company,dc=domain,dc=com"
strTGOU = "Laptops"
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set objComputer =
GetObject("winmgmts:{impersonationLevel=Impersonate}!\\" & _
strComputer & "\root\cimv2:Win32_ComputerSystem.Name='" & _
strComputer & "'")
strClientType = Left(UCase(strComputer), 2)
Select Case strClientType
Case "TG"
Set oRoot = GetObject("LDAP:")
' Set oOU = oRoot.OpenDSObject(strTGOU, strDomain & "\" &
strUser, strPassword, ADS_SECURE_AUTHENTICATION) '
IADsOpenDSObject
Set oOU = OpenDSObject(strTMOU, strDomain & "\" & strUser,
strPassword, ADS_SECURE_AUTHENTICATION) '
IADsOpenDSObject
Set oComputer = oOU.Create("Computer" , "cn=" & strComputer)
oComputer.Put "sAMAccountName", strComputer & "$"
objComputer.SetInfo
Set ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN +
ACCT_CREATE)
Set oOU = Nothing
Set oComputer = Nothing
Set ReturnValue = Nothing
' Set oOU = oRoot.OpenDSObject(strTGOU, strDomain & "\" &
strUser, strPassword, ADS_SECURE_AUTHENTICATION) '
IADsOpenDSObject
' ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN +
ACCT_CREATE)
' Set objMoveComputer = objOU.MoveHere("LDAP://CN=" & strComputer &
",CN=Computers,dc=biz,dc=es,dc-svm,dc=com", "CN=" & strComputer)
Case "TM"
Set oRoot = GetObject("LDAP:")
Set oOU = oRoot.OpenDSObject(strTMOU, strDomain & "\" &
strUser, strPassword, ADS_SECURE_AUTHENTICATION) '
IADsOpenDSObject
Set oComputer = oOU.Create("Computer" , "cn=" & strComputer)
oComputer.Put "sAMAccountName", strComputer & "$"
oComputer.Setinfo
MsgBox strComputer & " has been created in the " & strTMOU & "
container."
Set ReturnValue = objComputer.JoinDomainOrWorkGroup(strDomain,
strPassword, strDomain & "\" & strUser, NULL, JOIN_DOMAIN +
ACCT_CREATE)
MsgBox strComputer & " has been joined to the " & strDomain & "
Domain."
Set oRoot = Nothing
Set oOU = Nothing
Set oComputer = Nothing
Set ReturnValue = Nothing
End Select
Function GetResponse(sItem, sValue, sHint)
GetResponse = InputBox ( "Enter your " & sItem & vbCrlf & _
"then Click Ok." & vbCrlf & vbCrlf & _
"Example: " & sHint, "Remote
Authentication", sValue)
End Function
I have tried to specify the domain LDAP ont he oRoot line but with no
success. It's like it refuses to bind to the OU for some reason. Any
ideas? I know I'm not the only one trying to do this...
EricG
- Next message: Mark Whidby: "IP address script - takes too long"
- Previous message: mayayana: "Re: changing msgbox buttons"
- Next in thread: Steve Seguis [MVP]: "Re: Join a PC to the domain completely via VBScript with ADSI"
- Reply: Steve Seguis [MVP]: "Re: Join a PC to the domain completely via VBScript with ADSI"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|