Adding Address Information to Active Directory Users

I use the System.DirectoryServices.AccountManagement namespace classes to add and manage users in AD, but I cannot find how to add address information to user objects. I am using the UserPrincipal class to add users programmatically in AD.

Any ideas?

+4
source share
1 answer

Here is an example that can be done with an extensibility call:

class DSPrincipals { static void Main(string[] args) { /* Retreiving a principal context */ PrincipalContext domainContextMonou = new PrincipalContext(ContextType.Domain, "WM2008R2ENT:389", "ou=Monou,dc=dom,dc=fr", "jpb", " pass@1w0rd01 "); /* Create a user principal object */ slxUser aSlxUser = new slxUser(domainContextMonou, "W.Zeidan", " pass@1w0rd01 ", true); /* assign some properties to the user principal */ aSlxUser.GivenName = "Wessam"; aSlxUser.Surname = "Zeidan"; aSlxUser.streetAddress = "Add1"; /* Force the user to change password at next logon */ aSlxUser.ExpirePasswordNow(); /* save the user to the directory */ aSlxUser.Save(); Console.ReadLine(); } } [DirectoryObjectClass("user")] [DirectoryRdnPrefix("CN")] class slxUser : UserPrincipal { public slxUser(PrincipalContext context) : base(context) { } public slxUser(PrincipalContext context, string samAccountName, string password, bool enabled ) : base(context, samAccountName, password, enabled) { } [DirectoryProperty("streetAddress")] public string streetAddress { get { object[] result = this.ExtensionGet("streetAddress"); if (result != null) { return (string)result[0]; } else { return null; } } set { this.ExtensionSet("streetAddress", value); } } } 

For more information, see the MSDN documentation .

Here is the result:

enter image description here

+6
source

All Articles