0

I need to be able to compare the users active directory groups against a list of acceptable groups. This is not for authentication.

I know i can use System.DirectoryServices but i have seen many posts that say to use AccountManagement but all i see is .Active Directory.

Can anyone please assist me in the right direction?

mdarling
  • 77
  • 1
  • 13

1 Answers1

2

Try something like this: check out the System.DirectoryServices.AccountManagement (S.DS.AM) namespace. Read all about it here:

Basically, you can define a domain context and easily find users and/or groups in AD:

// set up domain context
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);

// find a user
UserPrincipal user = UserPrincipal.FindByIdentity(ctx, "SomeUserName");

if(user != null)
{
   PrincipalSearchResult<Principal> authgroups = user.GetAuthorizationGroups();

   // do your checking with the auth groups that the user has - against your list 
}

The new S.DS.AM makes it really easy to play around with users and groups in AD!

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459