diff --git a/MainWindow.xaml b/MainWindow.xaml index a6706154..2e138523 100644 --- a/MainWindow.xaml +++ b/MainWindow.xaml @@ -211,7 +211,7 @@ - + diff --git a/runspace.ps1 b/runspace.ps1 index daa00648..f8f9b01b 100644 --- a/runspace.ps1 +++ b/runspace.ps1 @@ -1,5 +1,5 @@ #for CI/CD -$BranchToUse = 'main' +$BranchToUse = 'test' <# .NOTES diff --git a/winutil.ps1 b/winutil.ps1 index acd8743c..d58322bf 100644 --- a/winutil.ps1 +++ b/winutil.ps1 @@ -1305,48 +1305,51 @@ $WPFtweaksbutton.Add_Click({ "HPSystemInformation" ) - ## Teams Removal - # 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() - # Remove Teams for Current Users - $localAppData = "$($env:LOCALAPPDATA)\Microsoft\Teams" - $programData = "$($env:ProgramData)\$($env:USERNAME)\Microsoft\Teams" - If (Test-Path "$($localAppData)\Current\Teams.exe") { - unInstallTeams($localAppData) + ## Teams Removal - Source: https://github.com/asheroto/UninstallTeams + function getUninstallString($match) { + return (Get-ChildItem -Path HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object { $_.DisplayName -like "*$match*" }).UninstallString } - elseif (Test-Path "$($programData)\Current\Teams.exe") { - unInstallTeams($programData) + + $TeamsPath = [System.IO.Path]::Combine($env:LOCALAPPDATA, 'Microsoft', 'Teams') + $TeamsUpdateExePath = [System.IO.Path]::Combine($TeamsPath, 'Update.exe') + + Write-Output "Stopping Teams process..." + Stop-Process -Name "*teams*" -Force -ErrorAction SilentlyContinue + + Write-Output "Uninstalling Teams from AppData\Microsoft\Teams" + if ([System.IO.File]::Exists($TeamsUpdateExePath)) { + # Uninstall app + $proc = Start-Process $TeamsUpdateExePath "-uninstall -s" -PassThru + $proc.WaitForExit() } - else { - Write-Warning "Teams installation not found" + + Write-Output "Removing Teams AppxPackage..." + Get-AppxPackage "*Teams*" | Remove-AppxPackage -ErrorAction SilentlyContinue + Get-AppxPackage "*Teams*" -AllUsers | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue + + Write-Output "Deleting Teams directory" + if ([System.IO.Directory]::Exists($TeamsPath)) { + Remove-Item $TeamsPath -Force -Recurse -ErrorAction SilentlyContinue } - # 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)" - } + + Write-Output "Deleting Teams uninstall registry key" + # Uninstall from Uninstall registry key UninstallString + $us = getUninstallString("Teams"); + if ($us.Length -gt 0) { + $us = ($us.Replace("/I", "/uninstall ") + " /quiet").Replace(" ", " ") + $FilePath = ($us.Substring(0, $us.IndexOf(".exe") + 4).Trim()) + $ProcessArgs = ($us.Substring($us.IndexOf(".exe") + 5).Trim().replace(" ", " ")) + $proc = Start-Process -FilePath $FilePath -Args $ProcessArgs -PassThru + $proc.WaitForExit() } - cmd /c winget uninstall -h "Microsoft Teams" - + + Write-Output "Restart computer to complete teams uninstall" + Write-Host "Removing Bloatware" foreach ($Bloat in $Bloatware) { - Get-AppxPackage "*$Bloat*" | Remove-AppxPackage - Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like "*$Bloat*" | Remove-AppxProvisionedPackage -Online + Get-AppxPackage "*$Bloat*" | Remove-AppxPackage -ErrorAction SilentlyContinue + Get-AppxProvisionedPackage -Online | Where-Object DisplayName -like "*$Bloat*" | Remove-AppxProvisionedPackage -Online -ErrorAction SilentlyContinue Write-Host "Trying to remove $Bloat." } @@ -1359,7 +1362,7 @@ $WPFtweaksbutton.Add_Click({ Write-Host -Object "Attempting to uninstall: [$($_.Name)]..." Try { - $Null = $_ | Uninstall-Package -AllVersions -Force -ErrorAction Stop + $Null = $_ | Uninstall-Package -AllVersions -Force -ErrorAction SilentlyContinue Write-Host -Object "Successfully uninstalled: [$($_.Name)]" } Catch {