Reputation:
How can I get the Active Directory groups the current user belongs to?
Is there a way to do this using the DirectoryServices.AccountManagement
library?
Upvotes: 11
Views: 12655
Reputation:
I found how. It turned out to be very simple with DirectoryServices.AccountManagement
:
using System.DirectoryServices.AccountManagement;
PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetGroups();
IEnumerable<string> groupNames = groups.Select(x => x.SamAccountName);
Upvotes: 27