Skip to content

Instantly share code, notes, and snippets.

@winfamy
Last active January 9, 2024 21:13
Show Gist options
  • Save winfamy/fab3f9db74ff7667e74bc1631a42de99 to your computer and use it in GitHub Desktop.
Save winfamy/fab3f9db74ff7667e74bc1631a42de99 to your computer and use it in GitHub Desktop.
adds members from distro list to a teams
$team = get-mgteam -Filter "startswith(displayname, 'S4S - All')"
$group = get-mggroup -Filter "startswith(displayname, 'S4S_All')"
$groupMembers = Get-MgGroupTransitiveMemberAsUser -GroupId $group.id -CountVariable GroupSearchCount -Sort "displayName" -ConsistencyLevel eventual -All
$teamMembers = Get-MgGroupTransitiveMemberAsUser -GroupId $team.id -CountVariable TeamSearchCount -Sort "displayName" -ConsistencyLevel eventual -All
$idsToAdd = (Compare-Object -ReferenceObject $teamMembers.id -DifferenceObject ($groupMembers.id) | where {$_.sideindicator -eq "=>"}).InputObject
foreach ($userid in $idsToAdd) {
new-mggroupmember -groupid $group.id -directoryobjectid $userid
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment