Hello,

I have 150 users under single ou=employees, I need to configure a script so
that it would configure addresses for the users. Here is what I got so far:

Const ADS_PROPERTY_UPDATE = 2
Set objUser = GetObject _
("LDAP://cn=whatever,ou=employees,dc=test,dc=org")

objUser.Put "streetAddress", "999 test st"
objUser.Put "l", "Boston"
objUser.Put "st", "MA"
objUser.Put "postalCode", "11111"
objUser.Put "c", "US"

objUser.PutEx ADS_PROPERTY_UPDATE, _
"postOfficeBox", Array

objUser.SetInfo


But this only does for single user, I don't want to go to 150 users
properties and update manually or retype the script user name everytime.

Thank you


Eimis

RE: Configuring addresses for users by maxv

maxv
Tue Sep 16 14:56:27 CDT 2003

You could perform an ADO query to locate all the users in the OU, then bind to each user as you loop through the collection.

Or you could bind to the container then set the filter to find user objects and enumerate the container:

dim oOU
set oOU = GetObject("LDAP://DN_OF_OU")
oOU.Filter = array("user")
for each oUsr in oOU
'
' put your user object code here
'
next

That would do it.

If you want the ADO query approach, then just ask, I will post the script.

Sincerely,
Max Vaughn [MS]
Microsoft Developer Support


Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use.


Re: Configuring addresses for users by Eimis

Eimis
Tue Sep 16 15:19:36 CDT 2003

Please post ADO query also !
Thank you very much !

Eimis


"Max L. Vaughn [MSFT]" <maxv@online.microsoft.com> wrote in message
news:%23jOObyIfDHA.3496@cpmsftngxa07.phx.gbl...
> You could perform an ADO query to locate all the users in the OU, then
bind to each user as you loop through the collection.
>
> Or you could bind to the container then set the filter to find user
objects and enumerate the container:
>
> dim oOU
> set oOU = GetObject("LDAP://DN_OF_OU")
> oOU.Filter = array("user")
> for each oUsr in oOU
> '
> ' put your user object code here
> '
> next
>
> That would do it.
>
> If you want the ADO query approach, then just ask, I will post the script.
>
> Sincerely,
> Max Vaughn [MS]
> Microsoft Developer Support
>
>
> Disclaimer: This posting is provided "AS IS" with no warranties, and
confers no rights. You assume all risk for your use.
>



Re: Configuring addresses for users by Richard

Richard
Tue Sep 16 17:32:30 CDT 2003

Eimis wrote:

> I have 150 users under single ou=employees, I need to configure a script
so
> that it would configure addresses for the users. Here is what I got so
far:
>
> Const ADS_PROPERTY_UPDATE = 2
> Set objUser = GetObject _
> ("LDAP://cn=whatever,ou=employees,dc=test,dc=org")
>
> objUser.Put "streetAddress", "999 test st"
> objUser.Put "l", "Boston"
> objUser.Put "st", "MA"
> objUser.Put "postalCode", "11111"
> objUser.Put "c", "US"
>
> objUser.PutEx ADS_PROPERTY_UPDATE, _
> "postOfficeBox", Array
>
> objUser.SetInfo
>
>
> But this only does for single user, I don't want to go to 150 users
> properties and update manually or retype the script user name everytime.

Hi,

If everyone has the same address, you could just bind to the OU, enumerate
the users, and assign the attributes:

Const ADS_PROPERTY_UPDATE = 2

Set objOU = GetObject("LDAP://ou=employees,dc=MyDomain,dc=com")
objOU.Filter = Array("user")
For Each objUser In objOU
objUser.Put "streetAddress", "999 test st"
objUser.Put "l", "Boston"
objUser.Put "st", "MA"
objUser.Put "postalCode", "11111"
objUser.Put "c", "US"
objUser.PutEx ADS_PROPERTY_UPUDATE, "postOfficeBox", Array("4012")
objUser.SetInfo
Next

Most likely, however, everyone has a different address. In that case I would
prepare a spreadsheet with the information required to update the users. The
program linked below demonstrates how to update users from the info in a
Microsoft Excel spreadsheet:

http://www.rlmueller.net/Read%20from%20Excel.htm

The program reads the Distinguished Name (DN) of users in the first column.
The first row is skipped (column headings) and a user is processed for each
subsequent row, until a blank row is encountered. The values for other
attributes are in the other columns. The program binds to each user object
in turn, assigns the attributes, then invokes SetInfo. You have to modify
the program to update your attributes rather than the ones used in this
example.

To create a spreadsheet of user Distinguished Names, you could modify this
example VBScript program:

http://www.rlmueller.net/Create%20User%20List%203.htm

As written it outputs all users in the domain. To modify the program to just
output the DN's of users in your one OU, you would replace this statement in
the program:

strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;subtree"

with this one:

strQuery = "<LDAP://ou=employees," & strDNSDomain & ">;" & strFilter _
& ";distinguishedName;oneLevel"

You would then have to add the address values in the other columns. I hope
this helps.

--
Richard
Microsoft MVP Scripting and ADSI
HilltopLab web site - http://www.rlmueller.net
--



Re: Configuring addresses for users by maxv

maxv
Thu Sep 25 09:14:06 CDT 2003

'*********************************************************************
' THIS SCRIPT IS PROVIDED AS AN ExAMPLE OF HOW TO QUERY THE ACTIVE DIRECTORY
' AND OBTAIN ALL OF THE USER OBJECTS WITHIN THE DIRECTORY.
' THE SAMPLE ILLUSTRATES HOW TO BIND TO THE RETURNED RESULTS
' AND DISPLAY SPECIFIC INFORMATION ABOUT EACH OBJECT
'
' THIS CODE MAKES NO ATTEMPT TO PERFORM PROPER ERROR CHECKING!
' THE SAMPLE USES THE RootDSE OBJECT TO DETERMINE THE
' DC NOMENCLATURE FOR THE LDAP SEARCH.
'
'
'
dim RootDse
set RootDse = GetObject("LDAP://RootDSE")
strdn = RootDse.Get("defaultNamingContext")
WScript.Echo "Preparing to query for all users in Domain: " & vbcrlf & strdn
WScript.Echo
'
' Create the objects needed to perform the ADO query
'
Set con = CreateObject("ADODB.Connection")
con.Provider = "ADsDSOObject"
con.Open "Active Directory Provider"
'
'Set Query syntax
'
Set Command = CreateObject("ADODB.Command")
Set Command.ActiveConnection = con
'
' Here is the LDAP query string.
' Change the "ou=Test Comp," to a container in your
' directory. If you want to start at the root, just remove
' the "ou=Text Comp" string.
'
Command.CommandText = "<LDAP://ou=test comp,"&strDN&">;(&(objectclass=user)(objectcategory=person));AdsPath, cn; subTree"
'
' With so many results to be returned, change the search to a paged search.
'
Command.Properties("Page Size") = 99
'
' Execute the query
'
Set rs = Command.Execute
'
' Loop through the records set and display the users'
' ADsPath and Common Name
'
' Commented out code illustrates how to force the users to change
' their password at the next login.
'
While Not rs.EOF
wscript.echo rs.Fields("cn").Value
WScript.echo rs.Fields("AdsPath").Value
rs.MoveNext
Wend
WScript.Echo "DONE............................"
'*********************************************************************

Sincerely,
Max Vaughn [MS]
Microsoft Developer Support


Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights. You assume all risk for your use.