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.


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

        Write-Host "Skip Team:$($Team.Alias) since $($Owner) is not a member"


Change the $user to the user you want to remove from the teams.

Connect to Microsoft Teams Powershell

And run the script.


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:



(Yes, I need to update the modules)

After that, we run the script:

And that is how you bulk remove Teams User!


Microsoft Docs

Other posts:
Add Exclusion to Microsoft Defender

2 thoughts on “Bulk remove Teams User”

Leave a Reply

Your email address will not be published. Required fields are marked *