Link to home
Start Free TrialLog in
Avatar of bjblackmore
bjblackmore

asked on

VBScript to Update Attributes for All Users in AD OU

Hi,

I need a vbscript that will update a single attribute for all users in an OU & subOU.

I've found a couple of vbscripts online, one which updates user attributes based on an array of users listed (having to manually create the array), and another which searches & lists all users in an OU & SubOU. So I have been trying to merge these 2 scripts, but without success. Can anyone tell me where I am going wrong?

Set objConnection = CreateObject("ADODB.Connection")
Set objCommand =   CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand.ActiveConnection = objConnection
Set rootDSE = GetObject("LDAP://RootDSE")

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

objCommand.CommandText = _
    "SELECT Name FROM 'LDAP://OU=testing,OU=users,OU=London,OU=Regional,dc=domain,dc=net' WHERE objectCategory='user'"  
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
        Set objUser = GetObject (objRecordSet.Fields("Name").Value)
        objUser.Put "l", "London"
        objUser.SetInfo
      objRecordSet.MoveNext
Loop

objRecordSet.Close
Set objRecordSet = Nothing
Set objCommand = Nothing
objConnection.Close
Set objConnection = Nothing

WSCript.Quit

Open in new window


The error i'm getting is invalid syntax on line ''Set objUser = GetObject (objRecordSet.Fields("Name").Value)'

Any help greatly appreciated

Ben
ASKER CERTIFIED SOLUTION
Avatar of bjblackmore
bjblackmore

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bjblackmore
bjblackmore

ASKER

Resolved myself after looking through other scripts