PowerShell – Microsoft Teams – Uninstaller

email me

This should be everything you need to kill Microsoft Teams (all versions, so be careful). I use a compiler to create EXEs, and then upload those to SCCM & Intune.

But you can test locally to make sure all the code is working fine before creating self-contained packages. Test in the SYSTEM account.

I do all my local testing like this:

psexec64 -s \\%computername% cmd
type whoami

To run powershell as SYSTEM, simply type powershell now.

 

Application Names

MSTeams_24165.1414.2987.41_x64__8wekyb3d8bbwe

MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe


Application GUID


{731F6BAA-A986-45A4-8936-7C3AAAAA760B}


Plugin GUID

{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91}


Registry

HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}

 

 

Code.ps1

Tested in the SYSTEM account.

# MrNetTek 
# eddiejackson.net 
# 7/24/2024
# free for public use 
# free to claim as your own

# PREP
$ErrorActionPreference = 'SilentlyContinue'
Stop-Process -Name Teams -Force -ErrorAction SilentlyContinue
Clear-Host

# Uninstall Modern Windows Apps - MSIX
Get-AppxPackage -AllUsers -Name "*MSTeams*" | Remove-AppxPackage -AllUsers

$uninstallAddinKey = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91}"
$uninstallString = (Get-ItemProperty -Path $uninstallAddinKey).UninstallString

if ($uninstallString) {
    Write-Output "Uninstalling Microsoft Teams Add-in..."    
	# This does nothing from the SYSTEM account. Terrible. 
	#DISABLED Start-Process -FilePath "msiexec.exe" -ArgumentList "/x {A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91} /quiet /norestart" -Wait -NoNewWindow	
	# This will work from the SYSTEM account, but isn't a real uninstall. Needs further research.
	#DISABLED Remove-Item -Recurse -Force "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91}"
    Write-Output "Uninstalling Microsoft Teams Add-in uninstalled."
} else {
    Write-Output "Uninstall string not found for Microsoft Teams Add-in."
}


# Uninstall Microsoft Teams Machine-Wide version
$uninstallKey = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}"
$uninstallString = (Get-ItemProperty -Path $uninstallKey).UninstallString

if ($uninstallString) {
    Write-Output "Uninstalling Microsoft Teams Machine-Wide version..."
    Start-Process -FilePath "msiexec.exe" -ArgumentList "/x {731F6BAA-A986-45A4-8936-7C3AAAAA760B} /quiet /norestart" -Wait -NoNewWindow
	Remove-ItemProperty -Force -Path "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run" -Name "TeamsMachineInstaller"
	Remove-Item -Recurse -Force "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}"
	Remove-Item -Recurse -Force "HKU:\.DEFAULT\Software\Microsoft\Office\Teams"
	Remove-Item -Recurse -Force "HKU:\S-1-5-18\Software\Microsoft\Office\Teams"
    Write-Output "Microsoft Teams Machine-Wide version uninstalled."
} else {
    Write-Output "Uninstall string not found for Microsoft Teams Machine-Wide version."
}


# Function to uninstall Microsoft Teams for a specific user profile
function Uninstall-TeamsForUser {
    param (
        [string]$userProfile,
        [string]$userSid
    )
    $uninstallString = [System.IO.Path]::Combine($userProfile, 'AppData', 'Local', 'Microsoft', 'Teams', 'Update.exe') + ' --uninstall -s'
    if (Test-Path ([System.IO.Path]::Combine($userProfile, 'AppData', 'Local', 'Microsoft', 'Teams', 'Update.exe'))) {
        Write-Output "Uninstalling Microsoft Teams for user profile: $userProfile"
        Start-Process -FilePath "cmd.exe" -ArgumentList "/c $uninstallString" -Wait -NoNewWindow
        Write-Output "--Microsoft Teams uninstalled for user profile: $userProfile"
    } else {
        Write-Output "Microsoft Teams is not installed for user profile: $userProfile"
    }
 
    
    # Delete the install registry key
    $teamsInstallRegistryPath = "Registry::HKEY_USERS\$userSid\SOFTWARE\Microsoft\Office\Teams"
    if (Test-Path $teamsInstallRegistryPath) {
        Write-Output "Removing Microsoft Teams Install registry entries for user SID: $userSid"
        Remove-Item -Recurse -Force $teamsInstallRegistryPath
        Write-Output "--Microsoft Teams Install registry entries removed for user SID: $userSid"
    } else {
        Write-Output "Microsoft Teams Install registry entries not found for user SID: $userSid"
    }
    
    
    
    # Delete the Uninstall registry key
    $teamsUninstallRegistryPath = "Registry::HKEY_USERS\$userSid\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Teams"
    if (Test-Path $teamsUninstallRegistryPath) {
        Write-Output "Removing Microsoft Teams Uninstall registry entries for user SID: $userSid"
        Remove-Item -Recurse -Force $teamsUninstallRegistryPath
        Write-Output "--Microsoft Teams Uninstall registry entries removed for user SID: $userSid"
    } else {
        Write-Output "Microsoft Teams uninstall registry entries not found for user SID: $userSid"
    }
 
    # Remove the Microsoft Teams classic (work or school) shortcut
    $teamsShortcut1Path = [System.IO.Path]::Combine($userProfile, 'AppData', 'Roaming', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Microsoft Teams classic (work or school).lnk')
    if (Test-Path $teamsShortcut1Path) {
        Write-Output "Removing Microsoft Teams classic (work or school) shortcut for user profile: $userProfile"
        Remove-Item -Force $teamsShortcut1Path
        Write-Output "--Microsoft Teams classic (work or school) shortcut removed for user profile: $userProfile"
    } else {
        Write-Output "Microsoft Teams classic (work or school) shortcut not found for user profile: $userProfile"
    }
     
     
    # Remove the Microsoft Teams (work or school) shortcut
    $teamsShortcut2Path = [System.IO.Path]::Combine($userProfile, 'AppData', 'Roaming', 'Microsoft', 'Windows', 'Start Menu', 'Programs', 'Microsoft Teams (work or school).lnk')
    if (Test-Path $teamsShortcut2Path) {
        Write-Output "Removing Microsoft Teams (work or school) shortcut for user profile: $userProfile"
        Remove-Item -Force $teamsShortcut2Path
        Write-Output "--Microsoft Teams (work or school) shortcut removed for user profile: $userProfile"
    } else {
        Write-Output "Microsoft Teams (work or school) shortcut not found for user profile: $userProfile"
    }
 
 
    # Remove the Teams User Folder
    $teamsUserPath = [System.IO.Path]::Combine($userProfile, 'AppData', 'Roaming', 'Microsoft', 'Teams')
    if (Test-Path $teamsUserPath) {
        Write-Output "Removing Microsoft Teams folder for user profile: $userProfile"
        Remove-Item $teamsUserPath -Recurse -Force
        Write-Output "--Microsoft Teams directory removed for user profile: $userProfile"
    } else {
        Write-Output "Microsoft Teams directory not found for user profile: $userProfile"
    }
}
 
# Get all user profiles and their SIDs
$userProfiles = Get-WmiObject Win32_UserProfile | Where-Object { $_.Special -eq $false } | Select-Object LocalPath, SID
 
# Uninstall Microsoft Teams for each user profile
foreach ($userProfile in $userProfiles) {
    Uninstall-TeamsForUser -userProfile $userProfile.LocalPath -userSid $userProfile.SID
}
 
# Uninstall Microsoft Teams for all users (SYSTEM account)
$teamsMachineWidePath = [System.IO.Path]::Combine($env:ProgramFiles, 'Teams Installer')
if (Test-Path $teamsMachineWidePath) {
    Write-Output "Uninstalling Microsoft Teams for all users..."
    Start-Process -FilePath "$teamsMachineWidePath\Teams.exe" -ArgumentList "--uninstall --system" -Wait -NoNewWindow
    Remove-Item -Recurse -Force $teamsMachineWidePath
    Write-Output "--Microsoft Teams uninstalled for all users."
} else {
    Write-Output "Microsoft Teams is not installed for all users."
}
 
# Remove Teams from the registry for all users
$teamsRegistryPath = "HKLM:\SOFTWARE\Microsoft\Teams"
if (Test-Path $teamsRegistryPath) {
    Write-Output "Removing Microsoft Teams registry entries..."
    Remove-Item -Recurse -Force $teamsRegistryPath
    Write-Output "--Microsoft Teams registry entries removed."
} else {
    Write-Output "Microsoft Teams registry entries not found."
}
 
# Remove Teams primary directory for all users
$teamsFolderPath = "C:\Program Files (x86)\Microsoft\Teams"
if (Test-Path $teamsFolderPath) {
    Write-Output "Removing Microsoft Teams directory..."
    Remove-Item -Recurse -Force $teamsFolderPath
    Write-Output "--Microsoft Teams folder removed."
} else {
    Write-Output "Microsoft Teams folder not found."
}
 
# Remove Teams PresenceAddin directory for all users
$teamsPresenceAddinPath = "C:\Program Files (x86)\Microsoft\TeamsPresenceAddin"
if (Test-Path $teamsPresenceAddinPath) {
    Write-Output "Removing Microsoft Teams PresenceAddin directory..."
    Remove-Item -Recurse -Force $teamsPresenceAddinPath
    Write-Output "--Microsoft Teams PresenceAddin folder removed."
} else {
    Write-Output "Microsoft Teams PresenceAddin folder not found."
}

# Remove the Microsoft Teams (work or school) shortcut for all users
$teamsShortcut3Path = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Teams (work or school).lnk"
if (Test-Path $teamsShortcut3Path) {
    Write-Output "Removing Microsoft Teams (work or school) shortcut for all users."
    Remove-Item -Force $teamsShortcut3Path
    Write-Output "--Microsoft Teams (work or school) shortcut removed for all users."
} else {
    Write-Output "Microsoft Teams (work or school) shortcut not found for all users."
}

# Remove the Microsoft Teams classic (work or school) shortcut for all users
$teamsShortcut4Path = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Teams classic (work or school).lnk"
if (Test-Path $teamsShortcut4Path) {
    Write-Output "Removing Microsoft Teams classic (work or school) shortcut for all users."
    Remove-Item -Force $teamsShortcut4Path
    Write-Output "--Microsoft Teams classic (work or school) shortcut removed for all users."
} else {
    Write-Output "Microsoft Teams classic (work or school) shortcut not found for all users."
}

# Bye, Felicia


 
 
 

Notes

 

The Windows client is deployed to the AppData folder located in the user’s profile

How the Microsoft Teams MSI package works

Clean up and redeployment procedure

PowerShell – Online Syntax Highlighter | Tomorrow Night Blue

Microsoft Charge with EU Anti-trust for Teams.

 

R&D Scripts I created while testing…

 

Code.cmd

CMD Script – Current User Account

:: MrNetTek 
:: eddiejackson.net 
:: 7/24/2024
:: free for public use 
:: free to claim as your own


@echo off
setlocal

:: Set the setup directory
set "setupDir=C:\setup"
if not exist "%setupDir%" mkdir "%setupDir%"

:: Terminate running Teams processes
taskkill /f /im teams.exe >nul 2>&1
taskkill /f /im TUninstall.exe >nul 2>&1

:: Uninstall Teams using TUninstall.exe - I include this EXE in the package
if exist "%setupDir%\TUninstall.exe" (
    start /wait "" "%setupDir%\TUninstall.exe" --uninstall -s
    timeout /t 5 
)

:: Uninstall Teams using Update.exe
if exist "%LOCALAPPDATA%\Microsoft\Teams\Update.exe" (
    "%LOCALAPPDATA%\Microsoft\Teams\Update.exe" --uninstall -s
    "%LOCALAPPDATA%\Microsoft\Teams\Update.exe" --uninstall --msiUninstall --source=default
)

if exist "C:\Program Files (x86)\Microsoft\Teams\Update.exe" (
    "C:\Program Files (x86)\Microsoft\Teams\Update.exe" --uninstall --msiUninstall --source=default
)

:: Delete Teams shortcut
del /q "%APPDATA%\Microsoft\Windows\Start Menu\Programs\Microsoft Teams.lnk" >nul 2>&1

:: Remove registry entries
for %%r in (
    "HKEY_CURRENT_USER\Software\Microsoft\Office\Teams"
    "HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{00425F68-FFC1-445F-8EDF-EF78B84BA1C7}"
    "HKEY_CURRENT_USER\SOFTWARE\Classes\CLSID\{d1b22d3d-8585-53a6-acb3-0e803c7e8d2a}"
    "HKEY_CURRENT_USER\SOFTWARE\Classes\ms-teams"
    "HKEY_CURRENT_USER\SOFTWARE\Classes\WOW6432Node\CLSID\{00425F68-FFC1-445F-8EDF-EF78B84BA1C7}"
) do (
    reg delete "%%r" /f /reg:64 >nul 2>&1
)

:: Delete Teams directories
if exist "%LOCALAPPDATA%\Microsoft\Teams" (
    rd /q /s "%LOCALAPPDATA%\Microsoft\Teams" >nul 2>&1
)
if exist "%APPDATA%\Microsoft\Teams" (
    rd /q /s "%APPDATA%\Microsoft\Teams" >nul 2>&1
)

:: Uninstall Teams MSI packages
MsiExec.exe /x{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91} /qn /norestart >nul 2>&1
MsiExec.exe /x{731F6BAA-A986-45A4-8936-7C3AAAAA760B} /qn /norestart >nul 2>&1

:: Remove Teams AppX packages using PowerShell
powershell -Command "Get-AppxPackage -Name MSTeams, MicrosoftTeams | Remove-AppxPackage" >nul 2>&1

:: Optional: Run additional cleanup script
if exist "%setupDir%\Uninstall-Teams.ps1" (
    powershell -NoProfile -ExecutionPolicy Bypass -File "%setupDir%\Uninstall-Teams.ps1"
)

timeout /t 10 
exit /b 0


 
 

Code.ps1

Uninstall-Teams.ps1 – Current User Account

# MrNetTek 
# eddiejackson.net 
# 7/24/2024
# free for public use 
# free to claim as your own
# see https://learn.microsoft.com/en-us/microsoftteams/scripts/powershell-script-deployment-cleanup


$ErrorActionPreference = 'Stop'

# Define the paths for Teams and its updater executable
$TeamsPath = Join-Path -Path $env:LOCALAPPDATA -ChildPath 'Microsoft\Teams'
$TeamsUpdateExePath = Join-Path -Path $TeamsPath -ChildPath 'Update.exe'

function Log-Message {
    param (
        [string]$Message
    )
    Write-Host $Message
}

try {
    # Check if the Update.exe exists and initiate the uninstall process
    if (Test-Path -Path $TeamsUpdateExePath) {
        Log-Message "Uninstalling Microsoft Teams..."

        # Start the uninstall process and wait for it to complete
        $proc = Start-Process -FilePath $TeamsUpdateExePath -ArgumentList "-uninstall -s" -NoNewWindow -PassThru
        $proc.WaitForExit()

        if ($proc.ExitCode -eq 0) {
            Log-Message "Microsoft Teams uninstalled successfully."
        } else {
            Log-Message "Uninstallation process exited with code $($proc.ExitCode)."
        }
    } else {
        Log-Message "Teams updater executable not found. Teams may not be installed."
    }

    # Remove the Teams directory if it exists
    if (Test-Path -Path $TeamsPath) {
        Log-Message "Deleting Teams directory..."
        Remove-Item -Path $TeamsPath -Recurse -Force
        Log-Message "Teams directory deleted."
    } else {
        Log-Message "Teams directory not found."
    }
} catch {
    Log-Message "An error occurred: $_"
    exit 1
}

exit 0


 
 

Code.cmd

CMD Script – SYSTEM Account

:: MrNetTek 
:: eddiejackson.net 
:: 7/24/2024 
:: free for public use 
:: free to claim as your own

@echo off

:: Uninstall from GUIDs
MsiExec.exe /x{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91} /qn /norestart
MsiExec.exe /x{731F6BAA-A986-45A4-8936-7C3AAAAA760B} /qn /norestart
:: 32
powershell.exe "remove-appxpackage MSTeams_24165.1414.2987.41_x64__8wekyb3d8bbwe"
powershell.exe "remove-appxpackage MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe"
:: 64
\\%computername%\C$\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "remove-appxpackage MSTeams_24165.1414.2987.41_x64__8wekyb3d8bbwe"
\\%computername%\C$\Windows\System32\WindowsPowerShell\v1.0\powershell.exe "remove-appxpackage MicrosoftTeams_24165.1306.2986.9504_x64__8wekyb3d8bbwe"

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760A}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760C}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760D}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760E}" /f /reg:64

reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760A}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760B}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760C}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760D}" /f /reg:64
reg delete "HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\{731F6BAA-A986-45A4-8936-7C3AAAAA760E}" /f /reg:64

timeout /t 5

exit /b 0


 
 

 
 

Discovery
 
Something interesting, I found trying to install the Teams Office Add-in failed testing in the SYSTEM account.

It works with these parameters:

msiexec /i C:\setup\MicrosoftTeamsMeetingAddinInstaller.msi /qn ALLUSERS=1 TARGETDIR=”C:\Program Files (x86)\Microsoft\TeamsMeetingAddin\1.24.14501.0″
 
 
I will add this into the script above to properly remove the Add-in from the SYSTEM account.
 
 
For Testing

Install Add-in MSI as just user. I’m using MSTeams-x64.msix, which also has the Add-in.
–C:\setup\MicrosoftTeamsMeetingAddinInstaller.msi

In system account, remove Add-in uninstall registry key.
–reg delete “HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\{A7AB73A3-CB10-4AA5-9D38-6AEFFBDE4C91}” /f /reg:64

In system account, install Add-in MSI.
–msiexec /i C:\setup\MicrosoftTeamsMeetingAddinInstaller.msi /qn ALLUSERS=1 TARGETDIR=”C:\Program Files (x86)\Microsoft\TeamsMeetingAddin\1.24.14501.0″

In user account, test Add-in in Outlook.

I successfully tested this, but there were orphaned reg keys in HKCU {shakes fist at MS}. I’m going to snapshot the process to see exactly what MS installs in HKCU. I’ll probably create a new post just for that.

See the Team’s Add-in Capture.
 
 
If there are still issues, set up a separate SCCM package to run as Current User, and link the Current package to the SYSTEM package (both packages will run in the correct security context then). It’s the best of both worlds.

try {
$tmaMsiPath = “{0}\MicrosoftTeamsMeetingAddinInstaller.msi” -f (get-appxpackage -name MSTeams).InstallLocation
$process = Start-Process -FilePath “msiexec.exe” -ArgumentList “/x `”$tmaMsiPath`” InstallerVersion=v3 /quiet /l `”$env:USERPROFILE\Downloads\tma-uninstall.log`”” -PassThru -Wait -ErrorAction Stop

if ($process.ExitCode -ne 0) {
throw “msiexec.exe exited with code $($process.ExitCode)”
}
else
{
Write-Host “Successfully uninstalled teams meeting addin.” -ForegroundColor Green
}
}
catch {
Write-Error “Failed to uninstall: $_. We’ll try repairing MSI”
$process = Start-Process -FilePath “msiexec.exe” -ArgumentList “/fav `”$tmaMsiPath`” /quiet /l `”$env:USERPROFILE\Downloads\tma-uninstall-repair.log`”” -PassThru -Wait -ErrorAction Stop

if ($process.ExitCode -ne 0) {
Write-Error “Repair failed with code $($process.ExitCode)”
}
else
{
Write-Output “Repair succeeded! We’ll try to uninstall again”
$process = Start-Process -FilePath “msiexec.exe” -ArgumentList “/x `”$tmaMsiPath`” /quiet InstallerVersion=v3 /l `”$env:USERPROFILE\Downloads\tma-uninstall-retry.log`”” -PassThru -Wait -ErrorAction Stop

if ($process.ExitCode -eq 0) {
Write-Host “Successfully uninstalled teams meeting addin.” -ForegroundColor Green
}
else
{
Write-Error “Could not uninstall teams meeting addin”
}
}
}