Setting and updating an Azure AD Group membership using the Microsoft Graph SDK for PowerShell.

Provided a target set of objectIds, this code will efficiently add and/or remove users from the specified group until their members are equal.

Sample Output

Set-MgGroupMembers $targetGroup $membersToApply

Assessing GroupA ... 2000 members.

  Members to add: 20
  Members to remove : 5

PowerShell Code

Note: This code requires the Microsoft Graph SDK for PowerShell.

Updated: