Microsoft Teams Uninstall, Reinstall, and Cleanup Guide & Scripts

Microsoft Teams is not like your average program when it comes to installing and uninstall it. The problem with Microsoft Teams is that it’s installed for every user, in the user’s AppData (or program data sometimes). Besides that, we also have Microsoft Teams machine-wide installer, which will automatically install Teams when a user logs in.

Cleaning things up with Microsoft Teams can be quite challenging. I tried for example to remove and re-install Teams for a user recently. The user got an error, Microsoft Teams Installation Has Failed with every update of Microsoft Teams

After removing everything and re-installing Teams he ended up with a blank Teams app. So no chat history and no more Teams channels (even though online everything was still visible).

In this article, I will give you some tips and scripts to remove and cleanup Teams so you can re-install it again.

Make Teams a bit more fun with these funny backgrounds for Microsoft Teams

Fix Microsoft Teams Installation Has Failed

One of the most common errors with Microsoft Teams is the error Installation Has Failed which can appear when Teams tries to update. This error can keep coming back with every update and is pretty annoying.

Simply re-installing Teams isn’t the solution. It will work for now, but the error will probably re-appear with the next update.

The only way to really fix the problem is to remove the local cache and restart Microsoft Teams:

  1. Close Microsoft Teams
  2. Press Windows key + R
  3. Type %appdata% and press enter
Fix Installation has failed error Teams
  1. Open the folder Microsoft
  2. Delete the folder Teams
Microsoft Teams Installation has Failed

5. Restart Teams

You can also use the the PowerShell script below to remove the Microsoft Teams Cache.

Uninstalling Microsoft Teams

We start with the easy part, simply uninstalling Microsoft Teams. Some people commented that their Microsoft Teams keeps reinstalling itself after they have uninstalled it. This is most of the time caused by the Machine-Wide installer.

So to completely uninstall Microsoft Teams you will have to remove both Microsoft Teams and the Teams Machine-Wide Installer.

  1. Open Settings > Apps > Apps & Features
  2. Search for Teams
  3. Remove all the apps (yes, I got two Machine-Wide installers… don’t ask why)
microsoft teams keeps reinstalling

Uninstall Microsoft Teams with PowerShell

I like to automate things as much as possible, so of course, we also have a PowerShell script to uninstall Microsoft Teams.

The script will remove the Machine-Wide installer and Microsoft Teams self. Make sure you run the PowerShell script in an elevated mode. You can do this by opening PowerShell as Admin

function unInstallTeams($path) {

	$clientInstaller = "$($path)\Update.exe"
	
	 try {
        $process = Start-Process -FilePath "$clientInstaller" -ArgumentList "--uninstall /s" -PassThru -Wait -ErrorAction STOP

        if ($process.ExitCode -ne 0)
		{
			Write-Error "UnInstallation failed with exit code  $($process.ExitCode)."
        }
    }
    catch {
        Write-Error $_.Exception.Message
    }

}

# Remove Teams Machine-Wide Installer
Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow

$MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
$MachineWide.Uninstall()

# Remove Teams for Current Users
$localAppData = "$($env:LOCALAPPDATA)\Microsoft\Teams"
$programData = "$($env:ProgramData)\$($env:USERNAME)\Microsoft\Teams"


If (Test-Path "$($localAppData)\Current\Teams.exe") 
{
	unInstallTeams($localAppData)
		
}
elseif (Test-Path "$($programData)\Current\Teams.exe") {
	unInstallTeams($programData)
}
else {
	Write-Warning  "Teams installation not found"
}

The script will check for the two possible installation locations of Teams and remove it when found.

If you want to run this script for multiple users (on the same computer), then you can use the following part in place of the Remove Teams for Current User section:

# Get all Users
$Users = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"

# Process all the Users
$Users | ForEach-Object {
        Write-Host "Process user: $($_.Name)" -ForegroundColor Yellow

        #Locate installation folder
        $localAppData = "$($ENV:SystemDrive)\Users\$($_.Name)\AppData\Local\Microsoft\Teams"
        $programData = "$($env:ProgramData)\$($_.Name)\Microsoft\Teams"

        If (Test-Path "$($localAppData)\Current\Teams.exe") 
        {
	        unInstallTeams($localAppData)
		
        }
        elseif (Test-Path "$($programData)\Current\Teams.exe") {
	        unInstallTeams($programData)
        }
        else {
	        Write-Warning  "Teams installation not found for user $($_.Name)"
        }
}

Uninstall Teams Machine-wide Installer

Just to be clear, you can safely uninstall the Teams Machine-wide installer. All it does is install Teams for every user that signs in.

You can uninstall the Teams Machine-wide installer in the settings screen or with a PowerShell script.

  1. Open Settings > Apps > Apps & Features
  2. Search for Teams
  3. Uninstall Teams Machine-Wide Installer
Uninstall Teams Machine-wide Installer

You can also remove the Teams Machine-Wide installer with PowerShell. This can be really useful if you need to remove it from multiple computers. Make sure you run the PowerShell script in an elevated mode.

You can open PowerShell as Administrator from start menu.

# Remove Teams Machine-Wide Installer
Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow

$MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
$MachineWide.Uninstall()

Microsoft Teams Clear Cache

So I had an occasion where I had to remove Microsoft Teams for users, but after re-installing Teams came back with no history. The only solution to fix this was to clear the cache of Microsoft Teams.

The problem is that there is not one location for the Microsoft Teams’ cache. I expected it to be in the roaming AppData, but it turned out to be not the only location. We also need to clear the Chrome and Edge Cache to completely remove it.

Mark Vale had already created a really nice PowerShell script to clear the Microsoft Teams Cache, so we are going to use that:

# Author: Mark Vale

$clearCache = Read-Host "Do you want to delete the Teams Cache (Y/N)?"
$clearCache = $clearCache.ToUpper()

if ($clearCache -eq "Y"){
    Write-Host "Stopping Teams Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Teams | Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Teams Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Clearing Teams Disk Cache" -ForegroundColor Yellow

    try{
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\application cache\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\databases" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\gpucache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Indexeddb" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Local Storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\tmp" | Remove-Item -Confirm:$false
        Write-Host "Teams Disk Cache Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Stopping Chrome Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Chrome| Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Chrome Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing Chrome Cache" -ForegroundColor Yellow
    
    try{
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cookies" -File | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Web Data" -File | Remove-Item -Confirm:$false
        Write-Host "Chrome Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Stopping IE Process" -ForegroundColor Yellow
    
    try{
        Get-Process -ProcessName MicrosoftEdge | Stop-Process -Force
        Get-Process -ProcessName IExplore | Stop-Process -Force
        Write-Host "Internet Explorer and Edge Processes Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing IE Cache" -ForegroundColor Yellow
    
    try{
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 2
        Write-Host "IE and Edge Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Cleanup Complete... Launching Teams" -ForegroundColor Green
    Start-Process -FilePath $env:LOCALAPPDATA\Microsoft\Teams\current\Teams.exe
    Stop-Process -Id $PID
}

This script will only clear the cache of Microsoft Teams and restart Teams when done.

You can also combine the cleanup and delete script to do everything in one run:

# Clearing Teams Cache by Mark Vale
# Uninstall Teams by Rudy Mens

$clearCache = Read-Host "Do you want to delete the Teams Cache (Y/N)?"
$clearCache = $clearCache.ToUpper()

$unistall = Read-Host "Do you want to uninstall Teams completely (Y/N)?"
$unistall = $unistall.ToUpper()


if ($clearCache -eq "Y"){
    Write-Host "Stopping Teams Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Teams | Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Teams Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Clearing Teams Disk Cache" -ForegroundColor Yellow

    try{
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\application cache\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\blob_storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\databases" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\gpucache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Indexeddb" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\Local Storage" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:APPDATA\"Microsoft\teams\tmp" | Remove-Item -Confirm:$false
        Write-Host "Teams Disk Cache Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Stopping Chrome Process" -ForegroundColor Yellow

    try{
        Get-Process -ProcessName Chrome| Stop-Process -Force
        Start-Sleep -Seconds 3
        Write-Host "Chrome Process Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing Chrome Cache" -ForegroundColor Yellow
    
    try{
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cache" | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Cookies" -File | Remove-Item -Confirm:$false
        Get-ChildItem -Path $env:LOCALAPPDATA"\Google\Chrome\User Data\Default\Web Data" -File | Remove-Item -Confirm:$false
        Write-Host "Chrome Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }
    
    Write-Host "Stopping IE Process" -ForegroundColor Yellow
    
    try{
        Get-Process -ProcessName MicrosoftEdge | Stop-Process -Force
        Get-Process -ProcessName IExplore | Stop-Process -Force
        Write-Host "Internet Explorer and Edge Processes Sucessfully Stopped" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Clearing IE Cache" -ForegroundColor Yellow
    
    try{
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 8
        RunDll32.exe InetCpl.cpl, ClearMyTracksByProcess 2
        Write-Host "IE and Edge Cleaned" -ForegroundColor Green
    }catch{
        echo $_
    }

    Write-Host "Cleanup Complete..." -ForegroundColor Green
}

if ($uninstall -eq "Y"){
    Write-Host "Removing Teams Machine-wide Installer" -ForegroundColor Yellow
    $MachineWide = Get-WmiObject -Class Win32_Product | Where-Object{$_.Name -eq "Teams Machine-Wide Installer"}
    $MachineWide.Uninstall()


    function unInstallTeams($path) {

	$clientInstaller = "$($path)\Update.exe"
	
	 try {
        $process = Start-Process -FilePath "$clientInstaller" -ArgumentList "--uninstall /s" -PassThru -Wait -ErrorAction STOP

        if ($process.ExitCode -ne 0)
		{
			Write-Error "UnInstallation failed with exit code  $($process.ExitCode)."
        }
    }
    catch {
        Write-Error $_.Exception.Message
    }

    }


    #Locate installation folder
    $localAppData = "$($env:LOCALAPPDATA)\Microsoft\Teams"
    $programData = "$($env:ProgramData)\$($env:USERNAME)\Microsoft\Teams"


    If (Test-Path "$($localAppData)\Current\Teams.exe") 
    {
	    unInstallTeams($localAppData)
		
    }
    elseif (Test-Path "$($programData)\Current\Teams.exe") {
	    unInstallTeams($programData)
    }
    else {
	    Write-Warning  "Teams installation not found"
    }

}

Wrapping Up

I hope these scripts helped you removing and cleaning up Microsoft Teams. If you want to re-install Microsoft Teams, then make sure you check out this article.

If you have any questions just drop a comment below.

Again thanks to Mark Vale for the clean up script!

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

9 thoughts on “Microsoft Teams Uninstall, Reinstall, and Cleanup Guide & Scripts”

  1. Teams refuses to sign into my corporate SSO infrastructure whenever I reboot, for whatever corner-case reason that our IT cannot figure out, and the easiest remedy is to reinstall it on each reboot. This script is perfect for automating such an annoying (and should-be-unecessary) task.
    One observation: Newer versions of PowerShell seem to dislike the Get-WmiObject cmdlet and so I was able to replace it with:
    Get-CimInstance -ClassName Win32_Product -Filter “Name = ‘Teams Machine-Wide Installer'”

  2. Hey Rudy,

    Rhis PS script is exactly what I need but I keep getting this error for both machine wide or local user uninstall scripts.

    You cannot call a method on a null-valued expression.
    At line:23 char:1
    + $MachineWide.Uninstall()
    + ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Any Ideas?

  3. Hi Rudy,

    I was trying your script to uninstall teams for all user so they can get the newest version of Teams. In this case it is a RDS environment with FS Logix in place. Because of FS Logix the profile folder is not on the session host when the user is logged off..so the script wont work on the session host..do you have a solution for this?

    Any help is appreciated!

    Regards,
    Guus

    • I am unfamiliar with FS Logix, but if I understand you correctly then your only option is to run the script when the user is logged in and run it in the user context. Maybe a simple scheduled task on the server that is triggered at login?

  4. Hi Rudy,

    Thanks again for a great post.

    I was trying to use your script to uninstall Teams for al users on an rds environment. This because I needed to update it and this seems the only way to get the job done..but I get an error for each user saying that no teams is found when clearly Teams is installed in the same path mentioned in your script..

    Any bright ideas how I can get my Teams updated on RDS?

    Any help is appropriated!

  5. Hi, I’m trying to uninstall Teams from my HP laptop. Was able to successfully uninstall the Teams program but every time I try to uninstall the Teams Machine-Wide Installer, after many minutes of nothing, I eventually get a “not responding” dialogue box and my system has to reboot. Tried multiple times with same outcome. Help?!?

  6. Hi,
    About the uninstallation for multiple users on the same computer:
    The uninstallation command for each user is intended to be run in the user session. Can you really run this per-user uninstallation command for every user from a unique admin session ?
    Even with admin rights you may not have write access to the users files, directories, registry entries.

    • As local admin you should have access to the users files. I used it last week and it was working fine. I did get some errors, but those were for the local admin user account.

Leave a Comment

0 Shares
Tweet
Pin
Share
Share