Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using (PrincipalContext PC = new PrincipalContext(ContextType.Domain, "165.1.5.25",
- "OU=Test,OU=Users,OU=Domain,dc=test,dc=dom", Environment.UserName, "admintest"))
- {
- using (UserPrincipal UsrP = new UserPrincipal(PC))
- try
- {
- UsrP.Name = "testuser";
- UsrP.SamAccountName = "testuser";
- UsrP.GivenName = "Test";
- UsrP.UserCannotChangePassword = false;
- UsrP.PasswordNeverExpires = true;
- UsrP.SetPassword("Qwerty123");
- UsrP.Enabled = true;
- UsrP.Description = "000";
- UsrP.EmailAddress = "testuser@test.ru";
- UsrP.VoiceTelephoneNumber = "2222";
- UsrP.Surname = "User";
- UsrP.DisplayName = "Test User";
- UsrP.UserPrincipalName = "testuser@gfx.dom";
- UsrP.Save();
- UserPrincipal user = UserPrincipal.FindByIdentity(PC, "testuser");
- GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "TEST_GROUP");
- group.Members.Add(user);
- group.Save();
- }
- catch (Exception ex)
- {
- _Log(ex.Message);
- }
- }
- [DirectoryRdnPrefix("CN")]
- [DirectoryObjectClass("Person")]
- public class UserPrincipalEx : UserPrincipal
- {
- public UserPrincipalEx(PrincipalContext context) : base(context)
- { }
- public UserPrincipalEx(PrincipalContext context,
- string samAccountName,
- string password,
- bool enabled) : base(context, samAccountName, password, enabled)
- { }
- [DirectoryProperty("physicalDeliveryOfficeName")]
- public string Office
- {
- get
- {
- if (ExtensionGet("physicalDeliveryOfficeName").Length != 1)
- return string.Empty;
- return (string)ExtensionGet("physicalDeliveryOfficeName")[0];
- }
- set { ExtensionSet("physicalDeliveryOfficeName", value); }
- }
- }
Add Comment
Please, Sign In to add comment