A Powershell Script to remove Microsoft Teams Classic

Bob Pendon 20 Reputation points
2024-05-20T05:45:02.89+00:00

Anyone who can share a powershell script that will remove Microsoft Teams Classic? Current script i have is that it will detect if Teams classic is installed then it will proceed to remove.

Check if Microsoft Teams Classic is installed

$teamsClassic = Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name LIKE '%Microsoft Teams%'" | Where-Object {$_.Name -like "Teams"}

if ($teamsClassic) {

Write-Host "Microsoft Teams Classic is installed."

$removeClassic = Read-Host "Do you want to remove Microsoft Teams Classic? (Y/N)"

if ($removeClassic -eq "Y" -or $removeClassic -eq "y") {

    Write-Host "Removing Microsoft Teams Classic..."

    $uninstallArgs = "/x $($teamsClassic.IdentifyingNumber) /quiet"

    Start-Process -FilePath "msiexec.exe" -ArgumentList $uninstallArgs -Wait

    Write-Host "Microsoft Teams Classic has been removed."

} else {

    Write-Host "Microsoft Teams Classic will not be removed."

}
```} else {

```yaml
Write-Host "Microsoft Teams Classic is not installed."
```}

# Check if new Microsoft Teams is installed

$teamsNew = Get-Package -Name "Teams Machine-Wide Installer" -ErrorAction SilentlyContinue

if ($teamsNew) {

```dockerfile
Write-Host "New Microsoft Teams is installed."
```} else {

```dockerfile
Write-Host "New Microsoft Teams is not installed."
```}
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,292 questions
Microsoft Teams Development
Microsoft Teams Development
Microsoft Teams: A Microsoft customizable chat-based workspace.Development: The process of researching, productizing, and refining new or existing technologies.
2,934 questions
PowerShell
PowerShell
A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
2,189 questions
0 comments No comments
{count} votes

Accepted answer
  1. Plamen Peev 80 Reputation points
    2024-05-20T15:13:06.1766667+00:00

    Hi @Bob Pendon , here is a solution that worked for me, please give it a try and mark this answer as "Accepted" if it worked for you. Tested on Windows 10 with PowerShell 7.4.2 and 5.1:

    $appName = "Microsoft Teams classic"
    # A function to search for Teams installation
    function Get-MSTeams {
        $path = @(
        "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall", 
        "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall", 
        "HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
        )
        $entry = Get-ChildItem -Path $path | Get-ItemProperty | where {$_.Displayname -match $appName}
        return $entry
    }
    
    # Assign the result to a variable, so you can use .InstallLocation method further down and trigger uninstallation
    $app = Get-MSTeams
    
    # Check if the function has returned result (Teams is installed)
    if ($app){
    
        # If yes, prompt for action
        $prompt = Read-Host "Microsoft Teams Classic installation FOUND. Uninstall? [Y/N]"
        
        if ($prompt -eq "Y"){
            Set-Location -Path $app.InstallLocation
            Start-Process Update.exe -ArgumentList "--uninstall", "-s"
            Write-Output "`nUninstalling..."
            Start-Sleep 5
    
            # Keep checking if Teams is still installed, until it's not
            while (Get-MSTeams){
                Start-Sleep 2
                Write-Output "Uninstalling..."
            }
            Write-Output "`nMicrosoft Teams Classic successfully uninstalled!`n"
        }
        else {break}
    }
    else {
        Write-Output "Microsoft Teams Classic installation NOT found!"
    }
    
    # Set location to home directory
    Set-Location $HOME
    
    
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. JiSheng-MSFT 695 Reputation points Microsoft Vendor
    2024-05-20T07:47:16.57+00:00

    Hi @Bob Pendon

    Teams tag is mainly focused on the general issue of Microsoft Teams troubleshooting. According to your description, your question is related to PowerShell script which is not in our support scope. To better help you solve your problem, we have added the PowerShell tag to your post.

    Thanks for your understanding and patience!

    0 comments No comments