Link to home
Start Free TrialLog in
Avatar of fatco
fatco

asked on

Query Active Directory for specific user information

I need to query AD for specific information on about 300 users. I need to find out the following for each - Exchange Sever, Message Store and Exchange Database Name. I have a list of users by FirstName LastName. I realize I may have to get the username to make this easier. I've used Saved Queries before to find Disabled Users but never to find specific info on a specific list of users. This AD structure is very large with over 20 seperate Exchange Servers and 30,000+ users.

Thanks
JT
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image


Hmm Firstname and lastname introduces a serious amount of work. We cannot guarantee unique matches on those, do you prefer to aim for getting the username? Or do we go ahead with just those?

I'll pop together some samples in Vb.NET for you to play with.

Chris

The attached shows how we might use the DirectorySearcher to find users when all we have is the givenName and sN attributes.

The match isn't certain we must use FindAll(), because of the size of the domain we're likely to contend with multiple results for each search.

The attribute that contains the information you're after is "homeMDB". It contains everything, although getting that information out of the string takes a bit of work.

Chris
imports System.DirectoryServices
...
Dim searchFilter As String = "(&(givenName=Chris)(sn=Dent))"
Dim domainRoot As New DirectoryEntry()
Dim ldapSearch As New DirectorySearcher(domainRoot, searchFilter)
ldapSearch.PropertiesToLoad.Add("homeMDB")
Dim ldapSearchResults As SearchResultCollection = ldapSearch.FindAll()
 
Dim ldapSearchResult As SearchResult
For Each ldapSearchResult In ldapSearchResults
   Label1.Text = ldapSearchResult.Properties("homemdb")(0).ToString()
Next

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Dent
Chris Dent
Flag of United Kingdom of Great Britain and Northern Ireland image

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
SOLUTION
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 fatco
fatco

ASKER

Sorry for the delay and thanks for the suggestions. I posted this question just before taking a few days off so I am just now getting back to it. This is exactly what I am looking for, some examples of scripts to mine out this information. I'll look these over this afternoon and respond.

JT
Avatar of fatco

ASKER

As I am not highly experienced with running scripts it will take me a little time to work with these but I am confident they will be a good starting point to complete my project. Thanks for the help!