Directory Services

Setting Properties Displayed on Property Pages

This topic provides code examples for setting the properties that appear in the property pages for users, which is accessed through the Active Directory Users and Computers MMC snap-in. If you have not used this snap-in before, you can open it on the server by selecting Start>All Programs>Administrative Tools>Active Directory Users and Computers. In the Users folder, right-click on a user name and select Properties. If you are setting up an application that allows a user to change information such as a home address, this is a useful piece of code to add to your application.

The following code example shows how to set common properties displayed in the General page.

[C#]
usr.Properties["givenName"].Value = "New User";
usr.Properties["initials"].Value = "Ms";
usr.Properties["sn"].Value = "Name";
usr.Properties["displayName"].Value = "New User Name";
usr.Properties["description"].Value = "Vice President-Operation";
usr.Properties["physicalDeliveryOfficeName"].Value = "40/5802";
usr.Properties["telephoneNumber"].Value = "(425)222-9999";
usr.Properties["mail"].Value = "newuser@fabrikam.com";
usr.Properties["wWWHomePage"].Value = "http://www.fabrikam.com/newuser";
usr.Properties["otherTelephone"].AddRange(new 
string[]{"(425)111-2222","(206)222-5263"});
usr.Properties["url"].AddRange(new 
string[]{"http://newuser.fabrikam.com","http://www.fabrikam.com/officers"});
usr.CommitChanges();

The following code example shows how to set common properties displayed in the Address page.

[C#]
usr.Properties["streetAddress"].Value = "2050 Fabrikam Way NE";
usr.Properties["postOfficeBox"].Value = "S/2523";
usr.Properties["l"].Value = "Sammamish";
usr.Properties["st"].Value = "Washington";
usr.Properties["postalCode"].Value = "98074";
usr.Properties["c"].Value = "US";
usr.CommitChanges();

The following code example shows how to set common properties displayed in the Account page.

[C#]
usr.Properties["userPrincipalName"].Value = "newuser@fabrikam.com";
usr.Properties["sAMAccountName"].Value = "newuser";
usr.Properties["userWorkstations"].Value = "pluto,venus,jupiter";
usr.CommitChanges();