Friday, September 10, 2010
Register | Login



From Twitter
Big-Blog
Aug 15

Written by: slhilbert
8/15/2005 6:08 PM 

 

I wanted to be able to query Active Directory off of an objectGUID string.  This function does that.  For help getting the ObjectGUID from an object look here.  For formatting the ObjectGUID automatically look here.

Read the comment at the top of the function to see how to use it.

 

'This function is passed an ObjectGUID in the following format \15\b4\49\d8\95\5a\84\4b\88\eb\37\44\22\24\4d\5c and an Attribute name that you want returned

Public Function GetUserInfoUID(ByVal passUID As String, ByVal inType As String) As String

Try

Dim sPath As String = "LDAP://Server/DC=DomainName,DC=Root"

Dim myDirectory As New DirectoryEntry(sPath, "User To Login To LDAP With", "Password of User To Login To LDAP With") 'pass the user account and password for your Enterprise admin.

Dim mySearcher As New DirectorySearcher(myDirectory)

Dim mySearchResultColl As SearchResultCollection

Dim mySearchResult As SearchResult

Dim myResultPropColl As ResultPropertyCollection

Dim myResultPropValueColl As ResultPropertyValueCollection

'Build LDAP query

' mySearcher.Filter = ("(&(objectClass=user)(objectGUID=" & "15/b4/49/d8/95/5a/84/4b/88/eb/37/44/22/24/4d/5c" & "))")

'mySearcher.Filter = ("objectGUID=" & "15/b4/49/d8/95/5a/84/4b/88/eb/37/44/22/24/4d/5c")

' mySearcher.Filter = "(&(objectClass=user)(objectGUID=\15\b4\49\d8\95\5a\84\4b\88\eb\37\44\22\24\4d\5c))"

' mySearcher.Filter = "(&(objectClass=user)(objectGUID=\15\b4\49\d8\95\5a\84\4b\88\eb\37\44\22\24\4d\5c))"

mySearcher.Filter = ("(&(objectClass=user)(objectGUID=" & passUID & "))")

mySearchResultColl = mySearcher.FindAll

'I expect only one user from search result

Select Case mySearchResultColl.Count

Case 0

Return "Found Zero"

Exit Function

Case Is > 1

Return "Null"

Exit Function

End Select

'Get the search result from the collection

mySearchResult = mySearchResultColl.Item(0)

'Get the Properites, they contain the usefull info

myResultPropColl = mySearchResult.Properties

'Retrieve from the properties collection the display name and email of the user

myResultPropValueColl = myResultPropColl.Item(inType)

 

Return CStr(myResultPropValueColl.Item(0))

Catch ex As System.Exception

'If the attribute has no value than an error is returned.

'If an error is returned we retrun a blank.

Return ex.Message

End Try

End Function

Tags:

Your name:
Your email:
(Optional) Email used only to show Gravatar.
Your website:
Title:
Comment:
Security Code
Enter the code shown above in the box below
Add Comment   Cancel 



For years of ramblings check out the "Blogchive" on the upper right.

Search Blog
Minimize
Blogchive
Minimize

GetYourOwnTots.com - Eating My Tots Since 2005