Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript to Update Attributes for All Users in AD OU

Status
Not open for further replies.

bjblackmore

Programmer
Jul 10, 2002
5
GB
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?

Code:
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

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

Any help greatly appreciated

Ben
 
OK, think I fixed it, had to add 'Set objUser = GetObject ("LDAP://" &objRecordSet.Fields("Name").Value)'

Thanks

Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top