[Solved] Script to Uninstall Teams Machine-Wide Installer and Delete All Related Files

Script to uninstall teams machine wide installer from all user file and delete all releated files

After installing a new version of Microsoft Teams, you might notice that the Teams Machine-Wide Installer remains installed on your system. Additionally, the associated files can still reside in user profiles, potentially leading to security vulnerabilities. In this blog, we’ll guide you through the process of uninstalling the Teams Machine-Wide Installer and deleting its associated files using a PowerShell script. This script can also be deployed to multiple machines using Tanium, SCCM, or any other management tool.

 

Understanding the Vulnerabilities


1. Microsoft Teams Heap Buffer Overflow Vulnerability (September 2023)
CVE: CVE-2023-4863

Qualys QID: 378941

Vulnerable File: C:\Users\JohnDoe\AppData\Local\Microsoft\Teams\current\Teams.exe

 

2. Microsoft Teams Remote Code Execution Vulnerability (August 2023)
Qualys QID: 378755

Vulnerable File: C:\Users\JohnDoe\AppData\Local\Microsoft\Teams\current\Teams.exe

 

Leaving obsolete files on your system can expose you to these vulnerabilities. Hence, it’s crucial to ensure all related files are removed after uninstalling the Teams Machine-Wide Installer.

 

The PowerShell Script


Below is a PowerShell script that will help you uninstall the Teams Machine-Wide Installer and delete all associated files from user profiles. Before deploying this script in a production environment, make sure to test it on a few machines. While this script has been successfully installed on over 30,000 machines without any issues, it’s always a good practice to perform a pilot test.

 

powershell


# Uninstall Teams Machine-Wide Installer
$installer = Get-WmiObject -Query “SELECT * FROM Win32_Product WHERE Name=’Teams Machine-Wide Installer'”

if ($installer) {
$installer.Uninstall()
Write-Output “Teams Machine-Wide Installer uninstalled.”
} else {
Write-Output “Teams Machine-Wide Installer not found.”
}

# Delete Teams files from all user profiles
$userProfiles = Get-ChildItem -Path “$env:SystemDrive\Users” -Directory

foreach ($profile in $userProfiles) {
$teamsPath = “$($profile.FullName)\AppData\Local\Microsoft\Teams”
if (Test-Path -Path $teamsPath) {
Remove-Item -Path $teamsPath -Recurse -Force
Write-Output “Deleted Teams files from $($profile.FullName).”
} else {
Write-Output “Teams files not found in $($profile.FullName).”
}
}

# Delete Teams.exe from all user profiles
foreach ($profile in $userProfiles) {
$teamsExePath = “$($profile.FullName)\AppData\Local\Microsoft\Teams\current\Teams.exe”
if (Test-Path -Path $teamsExePath) {
Remove-Item -Path $teamsExePath -Force
Write-Output “Deleted Teams.exe from $($profile.FullName).”
} else {
Write-Output “Teams.exe not found in $($profile.FullName).”
}
}


How to Use the Script


1. Save the Script:
Copy the script and save it as a .ps1 file, for example, Remove-Teams.ps1.

 

2. Run the Script:


Open PowerShell as an Administrator.

 

Navigate to the directory where the script is saved.

 

Run the script by typing .\Remove-Teams.ps1 and pressing Enter.

 

3. Deploying to Multiple Machines:


If you need to deploy this script to multiple machines, you can use management tools such as Tanium or SCCM. Both tools allow for deploying scripts across a network of computers.

Ensure you test the script in a controlled environment before a wide-scale deployment.

 

Testing the Script


Before deploying the script broadly, it’s important to test it on a few machines:

Identify Test Machines: Select a few machines that represent the diversity of your deployment environment.

 

Backup Data:

Ensure that any critical data is backed up before running the script.

 

Run the Script: Execute the script on the test machines and verify that it successfully uninstalls the Teams Machine-Wide Installer and removes all related files.

 

Monitor for Issues: Check the test machines for any issues that might arise from running the script. Ensure that no critical files or applications are affected.

 

Addressing Potential Issues
While the script has been tested and deployed to more than 30,000 machines without issues, it’s always good to be prepared for potential problems:

Script Fails to Uninstall: Ensure you have administrative privileges and that no other instances of Teams or related processes are running.

Residual Files: In some cases, residual files might remain if they are locked or in use. You may need to manually delete these files or schedule the script to run during system startup.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top