I am trying to use GroupPrincipal
(part of the System.DirectoryServices.AccountManagement
namespace) to populate a list of type string, so I can ch
This modification of your code works (I made tests to ensure):
using System.DirectoryServices.AccountManagement;
private static readonly string DomainName = "domaincontrollercomputer.domain.com";
private static readonly string DomainContainer = "DC=DOMAIN,DC=COM";
private static readonly string ADGroupName = "AD Group Name";
private List GroupName {get;set;}
private void populateGroups()
{
using (var ctx = new PrincipalContext(ContextType.Domain, DomainName, DomainContainer))
{
using (var grp = GroupPrincipal.FindByIdentity(ctx, ADGroupName))
{
GroupName = new List();
foreach (var member in grp.GetMembers())
{
GroupName.Add(member.SamAccountName);
}
}
}
}