I just finished a tenant to tenant migration where I had to migrate: “Teams, Exchange, OneDrive & SharePoint”. Therefore, I added a service account to all teams. After that, I needed to bulk remove the Teams user from all my Teams.
Of course, I used Powershell to do so.
Prerequisites
You need 1 Powershell module to run the script, “MicrosoftTeams”.
To install these modules, use the following script:
$Modules = "MicrosoftTeams" $InstalledModules = Get-InstalledModule foreach ($Module in $Modules) { If ($InstalledModules.name -notcontains $Module) { Write-Host "Installing module $$Module" Install-Module $Module -Force } Else { Write-Host "$Module Module already installed" } }
After that, you are ready to start!
The script
The script is fairly simple. This is the syntaxis:
The script removes the user if it is a member of the team. If the user is not a member of the team, the script will skip the team.
Optionally, you can enable the “-Role Owner”. If the user is the only Owner of the team. He/She will be removed.
$User = 'User You want to Remove' $Teams = Get-Team foreach ($Team in $Teams) { $Members = Get-TeamUser -GroupId $Team.GroupId If ($Members.User -contains $Owner) { Write-Host "Removing $($Owner) from $($Team.Alias)" Remove-TeamUser -GroupId $Team.GroupId -User $user #Optional: -Role Owner } else { Write-Host "Skip Team:$($Team.Alias) since $($Owner) is not a member" } }
Usage:
Change the $user to the user you want to remove from the teams.
Connect to Microsoft Teams Powershell
And run the script.
Example
It is always nice to see exactly what you need to do to run a certain script. That is what I will show you.
Firstly, we install the module:

In my case, the module is already installed.
After that, we connect to Microsoft Teams Powershell by using:
Connect-MicrosoftTeams
Result:

After that, we run the script:

And that is how you bulk remove Teams User!
References
Microsoft Docs
Other posts:
Add Exclusion to Microsoft Defender
[…] posts:Bulk remove teams userAdd exclusion in Attack Surface Reduction – Microsoft Defender for […]
[…] Microsoft Docs about AutoPilotOther Posts:Search for specific Mailbox PermissionsBulk Remove Teams User […]