Reputation: 584
I am trying to add a user to a group in AD, however the below example code no longer works:
UserPrincipal insUserPrincipal = (UserPrincipal)lbUsers.SelectedItem;
GroupPrincipal groupPrincipal =
GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName);
if (groupPrincipal.Members.Contains(insPrincipalContext,
IdentityType.SamAccountName, insUserPrincipal.SamAccountName))
{
MessageBox.Show(insUserPrincipal.Name +
" is already a member of group " + group.GroupName);
return;
}
groupPrincipal.Members.Add(insUserPrincipal);
groupPrincipal.Save();
Does anyone know how to do this in asp.net core 2.2? I cant find a new version.
GroupPrincipal.FindByIdentity(insPrincipalContext, group.GroupName); //No longer exists
Edit: I can use GroupPrincipal to search for groups etc - however the method FindByIdentity is missing
Upvotes: 1
Views: 773
Reputation: 387557
In order to use System.DirectoryServices.AccountManagement on .NET Core, you will need to install the NuGet package with the same name that provides this functionality. Once you have done that, you should be able to access the GroupPrincipal
type again.
Upvotes: 1