aacable79

Untitled

Mar 29th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. // Private Method
  2. private static void EnableADUserUsingUserPrincipal(string username)
  3. {
  4. try
  5. {
  6. PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);
  7. UserPrincipal userPrincipal = UserPrincipal.FindByIdentity
  8. (principalContext, username);
  9. userPrincipal.Enabled = true;
  10. userPrincipal.Save();
  11. MessageBox.Show("AD Account Enabled for {0}", username);
  12. Form1 f1 = new Form1();
  13. f1.StatusTextBox.Text = "Account Enabled";
  14.  
  15. }
  16. catch (Exception ex)
  17. {
  18. Console.WriteLine(ex.Message);
  19. }
  20. }
Add Comment
Please, Sign In to add comment