Last post Aug 11, 2009 02:07 PM by aheydeck
Aug 10, 2009 04:59 PM|aheydeck|LINK
Im just tearing my hair out from this problem; im trying to att a new user into the ad and at the same time add a member of group, but i cant get it to work.
My code is this:
Public Shared Function CreateVPNUser(ByVal Email As String, ByVal UserName As String, ByVal Password As String) As String
Dim de As New DirectoryEntry("LDAP://OU=Cafe_Users,DC=MyDC,DC=local", "MyUserName", "MyPassword")
Dim NewUser As DirectoryEntry = de.Children.Add("CN=" & UserName, "user")
NewUser.Properties("sAMAccountName").Value = (UserName)
NewUser.Properties("givenName").Value = ("VIC")
NewUser.Properties("sn").Value = ("User")
NewUser.Properties("mail").Value = (Email)
NewUser.Properties("description").Value = ("Registered from VICWeb")
NewUser.Properties("userPrincipalName").Value = (UserName & "@MyDC.local")
NewUser.Properties("userAccountControl").Value = 512
CreateVPNUser = "OK!"
Catch ex As Exception
CreateVPNUser = ex.Message
It works fine without :: NewUser.Properties("member").Add("VICVPN") ::, so this is what is causing the problem, however i need to add the new user to the group VICVPN. Can anyone please help me? I´ve searched the forums and cant really find a solution that
works for me...
I'd really appreciate it!
Aug 11, 2009 12:45 PM|raghu1|LINK
I noticed 2 issues:
1.Dim de As New DirectoryEntry("LDAP://OU=Cafe_Users,DC=MyDC,DC=local", "MyUserName", "MyPassword")
If the above points to your AD group, it probably s/be the CN
Dim de As New DirectoryEntry("LDAP://MyDomain/Cn=VICVPN,OU=Cafe_Users,DC=MyDC,DC=local", "MyUserName", "MyPassword")
2.You are trying to set the memberOf attribute of NewUser. You cannot set the memberOf. This is read only.
You need to point to de properly and set its member to NewUser's CN. Commit changes to the de which points to the group.The C# will be:
// Create the group object
DirectoryEntry ds = new DirectoryEntry();
ds.Path = LDAP://ADDomain/CN=The AD group Name,OU=...., DC=....
ds.Password=ThePassword of SomeAdminUser
ds.AuthenticationType = AuthenticationTypes.Secure;
// Add member to this group
ds.Properties["member"].Add(The full AD path of the member/user CN=New User, OU=...,Dc=...);
Aug 11, 2009 02:07 PM|aheydeck|LINK
Thanx! Got this working now!