开发者

Weird sAMAccountName when creating user account using DirectoryServices

开发者 https://www.devze.com 2023-03-08 23:39 出处:网络
my C# code uses the DirectoryServices namespace to create domain user accounts. DirectoryEntry deRoot = new DirectoryEntry(\"LDAP://OU=MYOU,DC=DOMAIN,DC=LOCAL\");

my C# code uses the DirectoryServices namespace to create domain user accounts.

    DirectoryEntry deRoot = new DirectoryEntry("LDAP://OU=MYOU,DC=DOMAIN,DC=LOCAL");
    directoryEntry = deRoot.Children.Add("CN=Tony", "user");
    directoryEntry.CommitChanges();
    directoryEnt开发者_开发技巧ry.Properties["sAMAccountName"].Value = "Tony1";
    directoryEntry.Properties["displayName"].Value = "Tony Danza";
    directoryEntry.Invoke("SetPassword", "mypass123");
    directoryEntry.CommitChanges();

This successfully creates the account but the sAMAccountName property contains a rather weird value like $HGA000-8FP94NQK9R9I or $NGA000-B3BJ2ELT5OOD. When executed inside my dev-domain, everything's fine.


Try setting the sAMAccountName before the first CommitChanges.

Maybe, since sAMAccountName is a required attribute, the system gives it a default value if you don't provide it when you create the object.

0

精彩评论

暂无评论...
验证码 换一张
取 消