Active Directory Users

saidev

Active member
Joined
Dec 22, 2005
Messages
27
Programming Experience
1-3
Hi Guys,

I am trying to add user to a Active Directory group which i already have access to but i am getting an error "Unspecified Error" Ca you guys please take a look at my code and let me know what i am doing worng? Appreciate your help. Thanks



Public Sub adUserToGroup()

Dim Buf As String = ""


Dim sDomainName As String = ("LDAP://servername.cfe.kineeg.com")
Dim adUserFolder As DirectoryEntry = New DirectoryEntry("OU=GroupsDC=cfe,DC=kineeg,DC=com")

Try


adUserFolder.Username = "name'"
adUserFolder.Password = "password"
Dim adSearch As New System.DirectoryServices.DirectorySearcher(adUserFolder)


adSearch.Filter = String.Format("(&(objectCategory=group)(sAMAccountName= {0}))", "AD Group Name i am trying to add users")

For Each x As SearchResult In adSearch.FindAll

Dim group As DirectoryEntry = x.GetDirectoryEntry

group.Properties("member").Add("CN=Testuser1,OU=UsersDC=cfe,DC=kineeg,DC=com")

group.CommitChanges()

Next


Catch ex As Exception

End Try

End Sub
 
Top Bottom