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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

AD - Get Account Profile Information

Status
Not open for further replies.

bakerm

Programmer
Apr 25, 2000
53
US
Hello,

I'm trying to get the profile path for a specific user in Active Directory.

I have the following code that will return all users:

Const ADS_PROPERTY_CLEAR = 1
Set objOU = GetObject("LDAP://ou=Users,dc=Work,dc=com")

objOU.Filter = Array("user")

For Each objUser In objOU
wscript.echo "Name: " & objUser.Name
wscript.echo "Profile Path: " & objUser.ProfilePath
Next

How can I filter the results so that information is returned for a specific user?

Thanks for any assistance!
 
Brute force method:
For Each objUser In objOU
If objUser.Name = "SpecificUser" Then
WScript.Echo "Profile Path: " & objUser.ProfilePath
End If
Next

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Thanks PHV!

I used your logic and it worked. Unfortunately, there are a few thousand users and this runs very slow as it has to iterate through the entire list of users.

Is there another method that can be used to get the inforamtion for a specific user, some sort of filtering?
 
Do a search for your user.

strUserName = "Test.User1"
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Open "Provider=ADsDSOObject;"
Set objCommand = CreateObject("ADODB.Command")
objCommand.ActiveConnection = objConnection
objCommand.CommandText = _
"<LDAP://dc=testdomain,dc=root>;(&(objectCategory=User)" & _
"(samAccountName=" & strUserName & "));samAccountName,ProfilePath;subtree"

Set objRecordSet = objCommand.Execute
WScript.Echo objRecordSet.Fields.Item("SamAccountName")
WScript.Echo objRecordSet.Fields.Item("ProfilePath")
objConnection.Close

dm4ever
--------------------------------------------------------------------------------
My approach to things: K.I.S.S - Keep It Simple Stupid
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top