Guest User

Untitled

a guest
Aug 29th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. using (PrincipalContext PC = new PrincipalContext(ContextType.Domain, "165.1.5.25",
  2. "OU=Test,OU=Users,OU=Domain,dc=test,dc=dom", Environment.UserName, "admintest"))
  3. {
  4. using (UserPrincipal UsrP = new UserPrincipal(PC))
  5. try
  6. {
  7. UsrP.Name = "testuser";
  8. UsrP.SamAccountName = "testuser";
  9. UsrP.GivenName = "Test";
  10. UsrP.UserCannotChangePassword = false;
  11. UsrP.PasswordNeverExpires = true;
  12. UsrP.SetPassword("Qwerty123");
  13. UsrP.Enabled = true;
  14. UsrP.Description = "000";
  15. UsrP.EmailAddress = "testuser@test.ru";
  16. UsrP.VoiceTelephoneNumber = "2222";
  17. UsrP.Surname = "User";
  18. UsrP.DisplayName = "Test User";
  19. UsrP.UserPrincipalName = "testuser@gfx.dom";
  20. UsrP.Save();
  21.  
  22. UserPrincipal user = UserPrincipal.FindByIdentity(PC, "testuser");
  23. GroupPrincipal group = GroupPrincipal.FindByIdentity(ctx, "TEST_GROUP");
  24. group.Members.Add(user);
  25. group.Save();
  26. }
  27. catch (Exception ex)
  28. {
  29. _Log(ex.Message);
  30. }
  31.  
  32. }
  33.  
  34. [DirectoryRdnPrefix("CN")]
  35. [DirectoryObjectClass("Person")]
  36. public class UserPrincipalEx : UserPrincipal
  37. {
  38. public UserPrincipalEx(PrincipalContext context) : base(context)
  39. { }
  40.  
  41. public UserPrincipalEx(PrincipalContext context,
  42. string samAccountName,
  43. string password,
  44. bool enabled) : base(context, samAccountName, password, enabled)
  45. { }
  46.  
  47. [DirectoryProperty("physicalDeliveryOfficeName")]
  48. public string Office
  49. {
  50. get
  51. {
  52. if (ExtensionGet("physicalDeliveryOfficeName").Length != 1)
  53. return string.Empty;
  54.  
  55. return (string)ExtensionGet("physicalDeliveryOfficeName")[0];
  56. }
  57. set { ExtensionSet("physicalDeliveryOfficeName", value); }
  58. }
  59. }
Add Comment
Please, Sign In to add comment