Last active
January 9, 2024 21:13
-
-
Save winfamy/fab3f9db74ff7667e74bc1631a42de99 to your computer and use it in GitHub Desktop.
adds members from distro list to a teams
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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