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()

$uninstall= Read-Host "Do you want to uninstall Teams completely (Y/N)?"
$uninstall= $uninstall.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 remove and clean 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.

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

  1. When I get to the uninstall from all users, I get this and the uninstall fails:
    unInstallTeams : This command cannot be run due to the error: Access is denied.

    I have tried and tried to get past this error but I have been completely unsuccessful. I am still working on it. I have use the system account, the local admin, a domain admin, but so far, it will not work.

  2. Hi Rudy,

    Thanks for this script.

    I am getting some errors, but I do not know if its related to some restrictive GPO’s we have in place for powershell or if others are getting this as well.

    I modified the following to troubleshoot:

    #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”)
    {
    Write-Host “local app data variable = ” $localAppData
    unInstallTeams($localAppData)

    }

    and I get :

    Process user: s
    local app data variable = C:\Users\s\AppData\Local\Microsoft\Teams
    unInstallTeams : UnInstallation failed with exit code -1.
    At C:\Temp\removeteamsnew.ps1:32 char:11
    + unInstallTeams($localAppData)
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,unInstallTeams

    Weirdly enough, it manages to delete the “current” folder inside the $localAppData but leaves the .dead and update.exe file in place.

    Maybe this is an unspecified error that update.exe –uninstall /s is throwing and being caught?

  3. This is an excellent script…thank you for publishing! However, I need it to be remotely executable. How best would you configure this script so it doesn’t require user interaction?

    Thank you!

    Respectfully…

  4. Does running ‘update.exe –uninstall’ from a user’s local app data remove teams for all other users as well? I’ve added a file version check to your script so that in theory only profiles with outdated versions will be affected. This seemed to worked fine as I have .dead in the previously outdated profile… but now teams will not launch on up-to-date profiles. The up-to-date profiles appear to be skipped due to version check and still have all files (no .dead). Thoughts?

  5. When i load the script in ISE and start ISE as an admin, the script is walking thru the different accounts. On some accounts it cannot find Teams installation but where Teams is installed it says:
    uninstallation Teams failed with exit code 1:18 char 11
    uninstallteams($programdata)
    notspecified (:) [write-error].writeerrorexecption.

    • Replace the line uninstallteams($programdata) with :
      write-host $programdata

      And check if that is a valid path. Seems like there is something wrong with the path.

  6. Hi super, we are struggling with this because many times users have problems with logging in: there is an error occured.
    When i start the script for uninstalling multiple users then a error occures: uninstallteams is nog recognised as a cmdlet….?

  7. Thanks for the script. Exactly what I was looking for. With the 2nd script by Mark to remove cache, it looks like it is for a single user case. Are you able to modify it to do a recursive delete for all users on the RDS server ?

    • Just wrap it in this foreach loop


      # Get all Users
      $Users = Get-ChildItem -Path "$($ENV:SystemDrive)\Users"
      # Process all the Users
      $Users | ForEach-Object {

      }

      And change the $env:APPDATA to $($ENV:SystemDrive)\Users\$($_.Name)\AppData\Roaming

  8. One other item to remove from the appdata local would be the squirell temp directory. That will cause reinstalls to fail. If that is cleaned up in one of the scripts above, sorry for not reading all the way thru.

      • lol I was just being a smartass, but given that MS fired all their QA testers and corporate customers have since effectively been the QA testers I’m not surprised they went this route. Maybe I don’t know any better but I feel that this is a really sloppy setup. Wonder if SfB 2016 was set up the same way.

  9. Hey Rudy

    This is exactly what I needed since I suspect our Teams deployment has gone wrong and I need to remove it from multiple computers and user profiles.
    However:

    I get the same error as mentioned above

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

    But when I run Get-WmiObject -Class Win32_Product

    I can see:
    IdentifyingNumber : {731F6BAA-A986-45A4-8936-7C3AAAAA760B}
    Name : Teams Machine-Wide Installer
    Vendor :
    Version :
    Caption : Teams Machine-Wide Installer

    Can I just use the ID number to instead of name to find it ?

  10. does this work?
    $programData = “$($env:ProgramData)\$($env:USERNAME)\Microsoft\Teams”
    that path doesn’t exist…and makes no sense to me

    • Yes, it works and no it doesn’t make sense ;). This is part of the whole problem with the Teams installation. On some deployments, Teams gets installed in C:\ProgramData\\Microsoft\Teams.

      The test-path should skip it if it doesn’t exist.

  11. 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'”

  12. 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?

  13. 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?

  14. 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!

  15. 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?!?

  16. 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