object reference not set to an instance of an object when searching for user in active directory

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I tryed searching for an user in active directory using the code below but it gives me the error in the title of this post above:
<span style="font-size:small
<pre class="prettyprint lang-vb AD = New DirectoryEntry("LDAP://OU=SchoolOUhere,OU=Staff,DC=garrard,DC=ketsds,DC=net", "", "", AuthenticationTypes.Secure)
AD2 = New DirectoryEntry("LDAP://OU=_Groups,OU=Staff,DC=garrard,DC=ketsds,DC=net", "", "", AuthenticationTypes.Secure)
ADFind = New DirectorySearcher(AD)
group = AD2.Children.Find("CN=" + groupname)
Add a single user to a group;
ADFind.Filter = "(&(objectCategory=user)(cn=" + userID + "))"
Dim results As SearchResult
results = ADFind.FindOne
To add the users distinguished name to the member property on the group object, use the Add method.
DN = results.Properties("distinguishedName").Item(0).ToString()
group.Properties("member").Add(DN)
group.CommitChanges()[/code]
<br/>
<hr class="sig Once you eliminate the impossible, whatever remains, no matter how improbable, must be the truth. - "Sherlock holmes" "speak softly and carry a big stick" - theodore roosevelt. Fear leads to anger, anger leads to hate, hate leads to
suffering - Yoda. Blog - http://jefferycarlsonblog.blogspot.com/

View the full article
 
Back
Top