Hello all... I hope you can help as this is starting to drive me insane.
I have been set a task of writing a script that moves a computer from one OU to a new "Vista" OU in AD. The script works fine when logged into an account which has access to move a computer between OUs but if you log into one which doesnt, it fails to work. It doesnt seem to be passing the username and password through correctly.
I have blanked out any username/password/domain info from the script below for obvious reasons.
Any advice from a pro would be awesome.
Thanks..
Here comes the science bit..
Option Explicit
'=*=*=*=*=*=* Constants =*=*=*=*=*=*
Const ADS_SCOPE_SUBTREE = 2
Const CONNECTION_USERNAME = "domain\username"
Const CONNECTION_PASSWORD = "password"
Const VISTA_OU = "LDAP://OU=xxxxx,OU=xxxx,OU=Machines,DC=xx,DC=Domain,DC=xx"
Dim objNetwork: Set objNetwork = CreateObject("WScript.Network")
'=*=*=*=*=*=* Set up database connection =*=*=*=*=*=*
Dim objConnection: Set objConnection = CreateObject("ADODB.Connection")
Dim objCommand: Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties ("user ID") = CONNECTION_USERNAME
objConnection.Properties ("Password") = CONNECTION_PASSWORD
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "Select ADsPath FROM 'LDAP://dc=xx,dc=xxxxxx,dc=xxx' WHERE objectCategory='computer' AND name='" & objNetwork.ComputerName & "'"
'Execute command
Dim objRecordSet: Set objRecordSet = objCommand.Execute
'=*=*=*=*=*=* Move Machine =*=*=*=*=*=*
Dim strADsPath: strADsPath = objRecordSet.Fields("ADsPath").Value
Dim objOU: Set objOU = GetObject(VISTA_OU)
Call objOU.MoveHere(strADsPath, vbNullString)
I have been set a task of writing a script that moves a computer from one OU to a new "Vista" OU in AD. The script works fine when logged into an account which has access to move a computer between OUs but if you log into one which doesnt, it fails to work. It doesnt seem to be passing the username and password through correctly.
I have blanked out any username/password/domain info from the script below for obvious reasons.
Any advice from a pro would be awesome.
Thanks..
Here comes the science bit..
Option Explicit
'=*=*=*=*=*=* Constants =*=*=*=*=*=*
Const ADS_SCOPE_SUBTREE = 2
Const CONNECTION_USERNAME = "domain\username"
Const CONNECTION_PASSWORD = "password"
Const VISTA_OU = "LDAP://OU=xxxxx,OU=xxxx,OU=Machines,DC=xx,DC=Domain,DC=xx"
Dim objNetwork: Set objNetwork = CreateObject("WScript.Network")
'=*=*=*=*=*=* Set up database connection =*=*=*=*=*=*
Dim objConnection: Set objConnection = CreateObject("ADODB.Connection")
Dim objCommand: Set objCommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Properties ("user ID") = CONNECTION_USERNAME
objConnection.Properties ("Password") = CONNECTION_PASSWORD
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCommand.CommandText = "Select ADsPath FROM 'LDAP://dc=xx,dc=xxxxxx,dc=xxx' WHERE objectCategory='computer' AND name='" & objNetwork.ComputerName & "'"
'Execute command
Dim objRecordSet: Set objRecordSet = objCommand.Execute
'=*=*=*=*=*=* Move Machine =*=*=*=*=*=*
Dim strADsPath: strADsPath = objRecordSet.Fields("ADsPath").Value
Dim objOU: Set objOU = GetObject(VISTA_OU)
Call objOU.MoveHere(strADsPath, vbNullString)