How to remove Microsoft Teams Classic using Microsoft Intune

Overview

This knowledge base will demonstrate how to remove Microsoft Teams Classic using Microsoft Intune. 
To upgrade to the "new" Microsoft Teams using Teams Admin Center. Devicie recommends using Option 1.

The three options with step-by-step instructions will be demonstrated below:

Option 1: Using Win32 App
Option 2: Using Proactive remediations
Option 3: Using PowerShell

The below screenshot shows that "Microsoft Teams Classic" installed.

Steps for Option 1: Using Win32 App

1. Create the following scripts to be packaged, place all into a folder like C:\MSTeams.
install.ps1

 

<#
.SYNOPSIS
PowerShell script to bootstrap installations and configure applications for Intune
.DESCRIPTION
The script is designed to bootstrap the installation of and set configuration for apps in Intune
.PARAMETER
None
.INPUTS
None
.OUTPUTS
Transcript Log file stored in C:\Programdata\IntuneApps\<AppName>
.NOTES
Version: 1.0
Author: Devicie
Creation Date: 27/06/2024
Purpose/Change: Initial script development
.EXAMPLE
powershell.exe -noprofile -executionpolicy bypass -file .\AppInstaller.ps1
#>
# If we are running as a 32-bit process on an x64 system, re-launch as a 64-bit process
if ("$env:PROCESSOR_ARCHITEW6432" -ne "ARM64")
{
if (Test-Path "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe")
{
& "$($env:WINDIR)\SysNative\WindowsPowerShell\v1.0\powershell.exe" -ExecutionPolicy bypass -NoProfile -File "$PSCommandPath"
Exit $lastexitcode
}
}
#Script Variables
$AppName = "Uninstall Teams Classic"
$AppDir = "$($env:ProgramData)\IntuneApps\$($AppName)"
$TagFile = "$($AppDir)\$($AppName).tag"
$Transscript = "C:\Temp\IntuneLogs\Install-$AppName"
$MSILog = "C:\Temp\IntuneLogs\Install-$AppName"
# Create log directory
if (-not (Test-Path $($AppDir)))
{
Mkdir $($AppDir)
}
# Start logging
Start-Transcript $Transscript
# Install App
$Status = (Start-Process "$($PSScriptRoot)\teamsbootstrapper.exe" -ArgumentList '-u' -wait -PassThru).ExitCode
# Set Flag file for Intune Detection
if (($Status -eq 0) -or ($Status -eq 3010))
{
Set-Content -Path $TagFile -Value "Installed"
} else {
Write-Host "Install failed with error $($Status), check $($MSILog) for more information"
}
Stop-Transcript
Exit $Status

detection.ps1

 

#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"
}

Download teamsbootstrapper.exe

2. Before packaging the Win32 app, your folder should look like this:

3. After packaging the Win32 app, your folder should now have a install.intunewin file.

4. Navigate to Microsoft Intune portal, then select Apps then by platform: Windows

5. Select Add then select App type: Windows app (Win32)

6. Under App Information, click on Select app package file and navigate to C:\MSTeams to where install.intunewin sits.

Select install.intunewin, then select Open then select OK.

7. Under App Information, enter the required details then select Next.

8. Under Program, enter and select the following:
Install command:
%SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -windowstyle hidden -executionpolicy bypass -command .\install.ps1

Uninstall command:
nouninstall

Installation time required (mins): 60
Allow available uninstall: Yes
Install behaviour: System
Device restart behaviour: App install may force a device restart
Then select Next.

9. Under Requirements, select the following:
Operating system architecture: 64-bit
Minimum operating system: Windows 10 1903
Then select Next.

10. Under Detection rules, select the following:
Rules format: Use a custom detection script
Script file: detection.ps1 (from Step 3)
Run script as 32-bit process on 64-bit clients: No
Enforce script signature check and run script silently: No

11. Under Dependencies, leave as default and select Next.
12. Under Supersedence, leave as default and select Next.
13. Under Assignments, select assignment group and select Next.
14. Under Review + create, review all settings and select Create.

15. Go to the device, run Company Portal and select Sync. The Win32 Application will detect and remove Teams classic and install the new Microsoft Teams.

Steps for Option 2: Using Proactive Remediations
1. Navigate to Microsoft Intune portal, then select Devices.
2. Under Manage Devices, select Scripts and Remediations.
3. Under Remediations, select Create.

4. Under Basics, enter the following name, description and publisher, then select Next.

5. Under Settings, upload the following:
Detection script file: Save the below as detection.ps1

 

$TeamsClassic = Test-Path C:\Users\*\AppData\Local\Microsoft\Teams\current\Teams.exe
$TeamsNew = Get-ChildItem "C:\Program Files\WindowsApps" -Filter "MSTeams_*"

if(!$TeamsClassic -and $TeamsNew){
Write-Host "Found it!"
exit 0
}else{
exit 1
}

Remediation script file: Save the below as remediation.ps1 

function Uninstall-TeamsClassic($TeamsPath) {
try {
$process = Start-Process -FilePath "$TeamsPath\Update.exe" -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"
## Get all subkeys and match the subkey that contains "Teams Machine-Wide Installer" DisplayName.
$MachineWide = Get-ItemProperty -Path $registryPath | Where-Object -Property DisplayName -eq "Teams Machine-Wide Installer"

if ($MachineWide) {
Start-Process -FilePath "msiexec.exe" -ArgumentList "/x ""$($MachineWide.PSChildName)"" /qn" -NoNewWindow -Wait
}
else {
Write-Host "Teams Machine-Wide Installer not found"
}

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

# Process all Users
foreach ($User in $AllUsers) {
Write-Host "Processing user: $($User.Name)"

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

if (Test-Path "$localAppData\Current\Teams.exe") {
Write-Host " Uninstall Teams for user $($User.Name)"
Uninstall-TeamsClassic -TeamsPath $localAppData
}
elseif (Test-Path "$programData\Current\Teams.exe") {
Write-Host " Uninstall Teams for user $($User.Name)"
Uninstall-TeamsClassic -TeamsPath $programData
}
else {
Write-Host " Teams installation not found for user $($User.Name)"
}
}

# Remove old Teams folders and icons
$TeamsFolder_old = "$($ENV:SystemDrive)\Users\*\AppData\Local\Microsoft\Teams"
$TeamsIcon_old = "$($ENV:SystemDrive)\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft Teams*.lnk"
Get-Item $TeamsFolder_old | Remove-Item -Force -Recurse
Get-Item $TeamsIcon_old | Remove-Item -Force -Recurse

Run this script using the logged-on credentials: No
Enforce script signature check: No
Run script in 64-bit PowerShell: Yes

Then select Next.
6. Under Scope Tags, leave as default and select Next.
7. Under Assignments, select your assignments and select Next.
8. Under Review + create, review all settings and select Create.

Steps for Option 3: Using PowerShell
1. Navigate to Microsoft Intune portal, then select Devices.
2. Under Manage Devices, select Platform Scripts then select Add then select Windows 10 and later.

3. Under Basics, enter a name for the script. Then select Next.

4. Under Script settings, select the following:
Script location: You can save the following and upload as Remediation.ps1

function Uninstall-TeamsClassic($TeamsPath) {
try {
$process = Start-Process -FilePath "$TeamsPath\Update.exe" -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"
## Get all subkeys and match the subkey that contains "Teams Machine-Wide Installer" DisplayName.
$MachineWide = Get-ItemProperty -Path $registryPath | Where-Object -Property DisplayName -eq "Teams Machine-Wide Installer"

if ($MachineWide) {
Start-Process -FilePath "msiexec.exe" -ArgumentList "/x ""$($MachineWide.PSChildName)"" /qn" -NoNewWindow -Wait
}
else {
Write-Host "Teams Machine-Wide Installer not found"
}

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

# Process all Users
foreach ($User in $AllUsers) {
Write-Host "Processing user: $($User.Name)"

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

if (Test-Path "$localAppData\Current\Teams.exe") {
Write-Host " Uninstall Teams for user $($User.Name)"
Uninstall-TeamsClassic -TeamsPath $localAppData
}
elseif (Test-Path "$programData\Current\Teams.exe") {
Write-Host " Uninstall Teams for user $($User.Name)"
Uninstall-TeamsClassic -TeamsPath $programData
}
else {
Write-Host " Teams installation not found for user $($User.Name)"
}
}

# Remove old Teams folders and icons
$TeamsFolder_old = "$($ENV:SystemDrive)\Users\*\AppData\Local\Microsoft\Teams"
$TeamsIcon_old = "$($ENV:SystemDrive)\Users\*\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Microsoft Teams*.lnk"
Get-Item $TeamsFolder_old | Remove-Item -Force -Recurse
Get-Item $TeamsIcon_old | Remove-Item -Force -Recurse

Run this script using the logged on credentials: No
Enforce script signature: No
Run script in 64-bit PowerShell Host: Yes
Select Next.

5. Under Assignments, select your assignments. Select Next.
6. Under Review + add, review your settings and select Add.

7. Go to the device, open Company Portal and select Sync.