-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathGet-ProductUninstallString.ps1
More file actions
36 lines (34 loc) · 1.41 KB
/
Get-ProductUninstallString.ps1
File metadata and controls
36 lines (34 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
$productNames = @("*Cisco*")
$UninstallKeys = @('HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall',
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall'
)
$results = foreach ($key in (Get-ChildItem $UninstallKeys) ) {
foreach ($product in $productNames) {
if ($key.GetValue("DisplayName") -like "$product") {
[pscustomobject]@{
KeyName = $key.Name.split('\')[-1];
DisplayName = $key.GetValue("DisplayName");
UninstallString = $key.GetValue("UninstallString");
Publisher = $key.GetValue("Publisher");
}
}
}
}
foreach ($key in $results) {
$uninstallString = $key.UninstallString
if ($uninstallString) {
if ($uninstallString.StartsWith('MsiExec.exe')) {
$uninstallString = $uninstallString.replace('/I','/X') + ' /qb- /quiet /passive /norestart'
} else {
$uninstallString += ' /quiet /silent'
$uninstallString = '"' + $uninstallString -replace "( \/.*)$","`"`$1"
}
Write-Output "Uninstalling $($key.DisplayName)"
Write-Output "$uninstallString"
# Uncomment to run the uninstall
#& cmd /c $uninstallString
} else {
Write-Host "No UninstallString found for $($key.DisplayName)"
}
}