I need to remove all users from my Microsoft Team in one command. The get-teamuser (first row) is giving me all the members. But I can't figure out how to now remove all in a loop. Think this should be something like the second row. But not sure how to do this.
Hope someone can help me with this issue.
Get-TeamUser -GroupId a4f03b48-49ae-4f06-949f-81b4940e17b6 | where-object {$_.role -eq "member"}
#Get-content c:\list.txt |foreach{Remove-TeamUser -GroupId a4f03b48-49ae-4f06-949f-81b4940e17b6 -User $_}
$users = Get-TeamUser -GroupId a4f03b48-49ae-4f06-949f-81b4940e17b6 | where-object {$_.role -eq "member"} Foreach ($user in $users) { $UPN = $user.userprinciplename
Remove-TeamUser -groupid "a4f03b48-49ae-4f06-949f-81b4940e17b6" -user "$UPN" }
Thanks Kartheek R,
I've used the answer above but modified it a bit to get it to work for me.
Connect-MicrosoftTeams
$TeamGUID = "94865df5-97fd-1234-aaad-13555de4gt28"
$users = Get-TeamUser -GroupId $TeamGUID | where-object {$_.role -eq "member"}
Foreach ($user in $users) {
$UPN = $user.User
Remove-TeamUser -groupid $TeamGUID -user $UPN
Write-Host $UPN
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.