Reputation: 79
I have some programs installed in Windows 10 and 7 that start with (in Uninstall Programs)
"Python info.data-5.332234" "Python delta.ind-5.332234" "Python module.data-15.332234" "Python hatch.back-0.332234"
I've tried various scripts to try and uninstall using partial match with PowerShell, but none of them seems to uninstall the programs.
This is the latest script I've used and does not work... it uninstalls the registry entry but not actually remove the folder or the entry from Uninstall Programs
$remove = @('Python info.data', 'Python delta.ind', 'Python module.data', 'Python hatch.back')
foreach ($prog_name in $remove) {
Write "Uninstalling" % $prog_name
$uninstall32 = gci "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall" | foreach { gp $_.PSPath } | ? { $_ -match $prog_name } | select UninstallString
if ($uninstall32) {
$uninstall32 = $uninstall32.UninstallString -Replace "msiexec.exe","" -Replace "/I","" -Replace "/X",""
$uninstall32 = $uninstall32.Trim()
Write "Uninstalling..."
Write $uninstall32
start-process "msiexec.exe" -arg "/X $uninstall32 /qn" -Wait}
}
Upvotes: 0
Views: 925
Reputation: 408
The Problem is, that the variable $uninstall32
can contain more than 1 entry.
Add a $uninstall32.GetType()
before you start msiexec to check if the variable may contains more than one string. If so, msiexec wont run because you are passing two GUIDs at once.
Use the Win32_Product WMI Class to get the GUIDs of the desired Applications.
$remove = @('Python info.data', 'Python delta.ind', 'Python module.data', 'Python hatch.back')
foreach ($prog_name in $remove) {
$uninstall32 = @(Get-WmiObject -Query "SELECT * FROM Win32_Product WHERE Name like '$prog_name%'")
foreach ($product in $uninstall32) {
Write "Uninstalling...`n$($product.Name)"
$exitCode = (Start-Process "msiexec.exe" -ArgumentList "/X $($product.IdentifyingNumber) /qn" -Wait -PassThru).ExitCode
Write "$($product.Name) return ExitCode: $exitCode"
}
}
Also, add the -PassThrue
Switch at the Start-Process
CMDLet and catch/output the ExitCode of each Uninstallation Process.
Make sure your Powershell/ISE is running with elevated privileges.
Upvotes: 1