From 2f12e9d24787e52bd992eecae647c4300ecb9a15 Mon Sep 17 00:00:00 2001 From: ItsBeardface <93796992+ItsBeardface@users.noreply.github.com> Date: Fri, 5 Nov 2021 18:23:03 -0400 Subject: [PATCH] Update Mysterious-MessyCode.ps1 --- Mysterious-MessyCode.ps1 | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/Mysterious-MessyCode.ps1 b/Mysterious-MessyCode.ps1 index 9372ef8..7c0047d 100644 --- a/Mysterious-MessyCode.ps1 +++ b/Mysterious-MessyCode.ps1 @@ -1 +1,36 @@ - $Uninstallers = Get-ChildItem HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*;($Uninstallers|% {$a=$_;Get-ItemProperty -name UninstallString -Path "$($a.name.replace('HKEY_LOCAL_MACHINE','HKLM:'))" -ErrorAction SilentlyContinue|? {(Get-ItemProperty -name DisplayName -Path $a.name.replace('HKEY_LOCAL_MACHINE','HKLM:')).DisplayName -like '*Carbon*'}}).UninstallString +function Delete-Things { + + $app = Read-Host -Prompt "What do you want to nuke?" + $app = "*" + $app + "*" + + $UninstallPaths = Get-ChildItem -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | + Get-ItemProperty | + Where-Object {$_.DisplayName -like $app} | + Select-Object -Property DisplayName, UninstallString, QuietUninstallString + + if ($UninstallPaths.count -eq 0){ + Write-Output "No results found. Try again." + return + } + + Write-Host ($UninstallPaths.count.ToString() + " results found.") + + ForEach($deleteThis in $UninstallPaths){ + $confirm = Read-Host -Prompt ("Do you want to remove " + $deleteThis.DisplayName + "? (Y/N)") + + if ($confirm.ToUpper() -ne "Y") { continue } + + if ($deleteThis.QuietUninstallString.Length -gt 0) { + $uninstStr = $deleteThis.QuietUninstallString + } + elseif ($deleteThis.UninstallString -like "msiexec*") { + $uninstStr = $deleteThis.UninstallString + " /qn /norestart" + + } else { + $uninstStr = $deleteThis.UninstallString + } + + Write-Host $uninstStr + & cmd /c $uninstStr + } +} \ No newline at end of file