Richard
Tue Jun 21 16:02:10 CDT 2005
Michelle Yu wrote:
> I need to retrived the office location for all the users in AD. Does
anyone
> has a vb script for this job?
Hi,
You want the value of the physicalDeliveryOfficeName attribute for all
users. You can use ADO to retrieve this. Here is a link to an example
VBScript program to retrieve the Distinguished Name's of all users:
http://www.rlmueller.net/Create%20User%20List%202.htm
This program can be revised to also retrieve office location. First, add the
physicalDeliveryOfficeName attribute to the comma delimited list of
attribute values to be retrieved:
strFilter = "(&(objectCategory=person)(objectClass=user))"
strQuery = "<LDAP://" & strDNSDomain & ">;" & strFilter _
& ";distinguishedName,physicalDeliveryOfficeName;subtree"
Then, in the loop that enumerates the recordset returned by ADO, retrieve
the value and write it out with Distinguished Name:
' Declare new variable strOffice.
Dim strOffice
' Enumerate all users. Write each user's Distinguished Name to the file.
Set objRecordSet = objCommand.Execute
Do Until objRecordSet.EOF
strDN = objRecordSet.Fields("distinguishedName")
strOffice = objRecordset.Fields("physicalDeliveryOfficeName")
objFile.WriteLine strDN & ";" & strOffice
objRecordSet.MoveNext
Loop
I separated the DN and office location with a semicolon, because DN's have
commas. For more info on using ADO to retrieve information from AD:
http://www.rlmueller.net/ADOSearchTips.htm
--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site -
http://www.rlmueller.net
--