diff --git a/Reinstall Scripts/App - Teams Nuke - Aggressive Reinstall.ps1 b/Reinstall Scripts/App - Teams Nuke - Aggressive Reinstall.ps1 new file mode 100644 index 0000000..f0a6a03 --- /dev/null +++ b/Reinstall Scripts/App - Teams Nuke - Aggressive Reinstall.ps1 @@ -0,0 +1,157 @@ +<# +Author: Gabe Kerntke +Date: 03-06-2024 + +.Synopsis + +.Modified +2024-03-06 (GabeK) - Original script created +2025-08-09 (GabeK) - Updated to use functions script +#> + +[CmdletBinding()] +Param( + [Parameter(Mandatory = $false)] + $App_Name = "Teams", + [Parameter(Mandatory = $false)] + $File_Name_Extension = "exe", + [Parameter(Mandatory = $false)] + $Install_Parameters = "-p" , + [Parameter(Mandatory = $false)] + $EPCache_Folder = "3rd Party Patches\$App_Name", + [Parameter(Mandatory = $false)] + $File_Name = "$App_Name.$File_Name_Extension", + [Parameter(Mandatory = $false)] + $users = (Get-ChildItem -path c:\users).name, + [Parameter(Mandatory = $false)] + $CurrentUser = ((get-ciminstance win32_computersystem | ForEach-Object username) -split '\\')[1] +) + +$initialURL = "https://learn.microsoft.com/en-us/microsoftteams/new-teams-bulk-install-client" +# Download the HTML content +$html = (New-Object System.Net.WebClient).DownloadString("$initialURL") + +# Split the content on ">" and "<" characters to extract the text content +$text = $html.Split([char[]]@(">", "<"), [StringSplitOptions]::RemoveEmptyEntries) + +# Sort the start and end index of the page +$startIndex = $text.IndexOf("Option 1A: Download and install new Teams for a single computer") +$endIndex = $text.IndexOf("Option 1B: Download and install new Teams using an offline installer") + +# Extract the rows +$rows = $text[$startIndex..$endIndex] + +# Filter out only the rows containing version numbers +$Sort = $rows | Where-Object { $_ -match "https" } +$Split = $Sort.split() | Select-Object -First 2 | Select-Object -Last 1 +$DownloadURL = $Split.Substring(5) -replace '"', "" + +#Region Functions + +Function Uninstall-Teams { + Stop-Process -name *teams* -Force -ErrorAction SilentlyContinue -Verbose + Start-Sleep 10 + $Applist = Get-Software | Where-Object { $_.DisplayName -like "*$Name*" } + $Uninstall = Get-WmiObject Win32_Product -filter "name like 'Teams%'" | ForEach-Object { $_.Uninstall() } -Verbose -ErrorAction SilentlyContinue + $Value = $Uninstall | Select-Object -ExpandProperty ReturnValue + + If ($Value -eq "0") { + Write-Host "Successfull uninstall via WmiObject" + Remove-TeamsFolder + } + ElseIf ($null -eq $Applist) { + Remove-TeamsFolder + } + Else { + $UninstallPath = $Applist | Select-Object -ExpandProperty PSPath + $B = $UninstallPath -replace "Microsoft.PowerShell.Core", "" + $C = $B.Substring(1) + Remove-Item -Path $C -Force + Start-Sleep 5 + Remove-TeamsFolder + } +} + +Function Remove-TeamsFolder { + $ErrorActionPreference = "SilentlyContinue" + + trap { + $message = $Error[0].Exception.Message + #If ($message) { + #Write-Host -Object "Error: $message" -ForegroundColor Red + # } + #exit -1 + } + Get-AppxPackage -name *Teams* -AllUsers | Select-Object -ExpandProperty PackageFullName | Remove-AppxPackage -AllUsers -ErrorAction SilentlyContinue + + Get-ChildItem "C:\Program Files\WindowsApps" | Where-Object { $_.Name -like "*Teams*" } | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue + + $programData = "$($env:ProgramData)\$($_.Name)\Microsoft\Teams" + If (Test-Path "$($programData)\Current\Teams.exe") { + Start-Process -FilePath "$($programData)\Current\Teams.exe" -ArgumentList "--uninstall /s" -PassThru -Wait + Remove-Item "$($env:ProgramData)\$($_.Name)\Microsoft\Teams" -Force -Recurse + } + + $users = Get-ChildItem C:\Users + foreach ($user in $users) { + $path = "C:\Users\$($user.Name)\AppData\Local\Microsoft\Teams" + If (Test-Path $path) { + Remove-Item $path -Force -Recurse + } + } + RegDelete +} + +Function RegDelete { + New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction SilentlyContinue | Out-Null + + foreach ($user in $users) { + If ($user -eq $currentuser) { continue; } + reg load "hku\$user" "C:\Users\$user\NTUSER.DAT" | Out-Null + # Do whatever you need with "hkey_users\$user" here which links to each users' HKU + If (Test-Path "HKU:$user\Software\Microsoft\Windows\CurrentVersion\Uninstall") { + Get-ChildItem "HKU:$user\Software\Microsoft\Windows\CurrentVersion\Uninstall" | Where-Object { $_ -like "*Teams*" } | Remove-Item -Force -Recurse -Verbose -ErrorAction SilentlyContinue + Start-Sleep 5 + } + } + + foreach ($user in $users) { + If ($user -eq $currentuser) { continue; } + Start-Sleep 5 + reg unload "hku\$user" | Out-Null + } + + $Keys = Get-ChildItem "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList\" -Recurse + $SIDs = $Keys.PSChildName + foreach ($SID in $SIDs) { + If (Test-Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall") { + Get-ChildItem "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall" | Where-Object { $_ -like "*Teams*" } | Remove-Item -Force -Recurse -Verbose -ErrorAction SilentlyContinue + } + If (Test-Path "HKU:\$SID\Software\Microsoft\Windows\CurrentVersion\Uninstall\*teams*") { + Write-Host "Teams uninstall key for $SID still exists." + } + } + <# + Foreach ($Key in $Keys) { + If (($key.GetValueNames() | ForEach-Object { $key.GetValue($_) }) -match "\b$CurrentUser\b" ) { $sid = $key } + } + + $sid = $sid.pschildname + + If (Test-Path "HKU:\$sid\Software\Microsoft\Windows\CurrentVersion\Uninstall") { + Get-ChildItem "HKU:\$sid\Software\Microsoft\Windows\CurrentVersion\Uninstall" | Where-Object { $_ -like "*Teams*" } | Remove-Item -Force -Recurse -ErrorAction SilentlyContinue + } + else { Write-Host "No Teams reg key under currently signed in user $CurrentUser" } + #> +} + +#Region Script Start +If ((Test-Path "C:\Temp\Script Cache") -eq $False) { New-Item -ItemType directory -Path "C:\Temp\Script Cache" } +Invoke-WebRequest -UseBasicParsing "https://scripts.gabesville.com/Gabesville/Powershell-Scripts/raw/branch/main/Functions%20Scripts/Functions.ps1" -outfile "C:\Temp\Script Cache\Functions.ps1" +. "C:\Temp\Script Cache\Functions.ps1" + +Close-App +Uninstall-Teams +Test-Probe_Online +Install-App +#Region Script End \ No newline at end of file