Created
May 29, 2024 04:56
-
-
Save contactbrenton/c28d49f04515a6d6a029c5a083c074ea to your computer and use it in GitHub Desktop.
Not my work
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | |
# 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)" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment