Active Directory new User account - howto set CN value

G

Guest

Hi, I am having trouble setting the user's cn value using VB .NET 2002 while
creating a new user account. The code is as below:

***********************Start of code****************************
Dim enTry As DirectoryEntry = New DirectoryEntry("LDAP://" + ldapStr)
Dim NewUser As DirectoryEntry = enTry.Children.Add("CN=" &
sAMAccountName, "User")

NewUser.Properties("sAMAccountName").Value = sAMAccountName
NewUser.Properties("Description").Add("Student imported on " +
Date.Now)
NewUser.Properties("mail").Add(mail)
NewUser.Properties("displayName").Add(givenName + " " + sn)
NewUser.Properties("cn").Add(givenName + " " + sn)
NewUser.Properties("name").Add(givenName + " " + sn)
NewUser.Properties("homeDirectory").Add(homeDirectory)
NewUser.Properties("homeDrive").Add(homeDrive)
NewUser.Properties("mobile").Add(mobile)
NewUser.Properties("telephoneNumber").Add(telephoneNumber)
NewUser.Properties("sn").Add(sn)
NewUser.Properties("givenName").Add(givenName)
NewUser.Properties("scriptPath").Add("students.bat")
NewUser.CommitChanges()
NewUser.Invoke("SetPassword", New Object() {password})
NewUser.CommitChanges()

**************************End of *************************

Error message "Additional information: An invalid dn syntax has been
specified" poped up and stopped at the first CommitChanges method. No error
message shown if I commented the set cn line. However, it is not what I
wanted as it will use the sAMAccountName for cn while I want to use the
user's full name as cn. How can I set the cn value?
 
G

Guest

Problem solved. I actually assigned the CN value to sAMAccountName while
creating the user object. :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top