Guest User

Untitled

a guest
Apr 20th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. UserPrincipal user = UserPrincipal.FindByIdentity(new PrincipalContext(ContextType.Domain, "<Domain>"), IdentityType.SamAccountName, "<UserName>");
  2. foreach (GroupPrincipal group in user.GetGroups())
  3. {
  4. Console.Out.WriteLine(group);
  5. }
  6.  
  7. String domainName = @"<your domain>";
  8. String username = domainName + @"<your username>";
  9. PrincipalContext thisDomain = new PrincipalContext(ContextType.Domain);
  10.  
  11. UserPrincipal userPrincipal = UserPrincipal.FindByIdentity(thisDomain, username);
  12.  
  13. PrincipalSearchResult<Principal> userGroups = userPrincipal.GetAuthorizationGroups();
  14.  
  15. foreach (Principal principal in userGroups.OfType<GroupPrincipal>())
  16. {
  17. Debug.WriteLine(principal.Name);
  18. }
Add Comment
Please, Sign In to add comment