user356178
user356178

Reputation:

Retrieve the Active Directory groups of the current user

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

Answers (1)

user356178
user356178

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

Related Questions