Skip to content

Instantly share code, notes, and snippets.

@DBremen
Last active February 14, 2016 19:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DBremen/2225b030b75388ad53c7 to your computer and use it in GitHub Desktop.
Save DBremen/2225b030b75388ad53c7 to your computer and use it in GitHub Desktop.
Retrieve Uninstall information for software packages from the registry
function Get-Uninstaller {
[CmdletBinding()]
Param(
$DisplayName = '*',
[ValidateSet('HKLM', 'HKCU')]
[string[]]$Hive = @('HKLM','HKCU')
)
$keys =@'
:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
:\SOFTWARE\WOW6432NODE\Microsoft\Windows\CurrentVersion\Uninstall
'@ -split "`r`n"
foreach ($currHive in $Hive){
foreach($key in $keys){
$key = "$currHive" + "$key"
if(Test-Path $key){
$subKeys = Get-ItemProperty "$key\*"
}
foreach($subKey in $subKeys){
if($subKey.DisplayName -like "$DisplayName" -and $subKey.UninstallString){
$uninstallString = $subKey.UninstallString
$modifyPath = $subKey.ModifyPath
$htProps = [Ordered]@{
RegistryHive=$currHive
DisplayName=$subKey.DisplayName;
UninstallString=$uninstallString.Replace('"','');
msiGUID='';
InstallLocation=$subKey.InstallLocation;
Version=$subKey.DisplayVersion
}
if($uninstallString -match "^msiexec"){
$htProps.msiGUID = [regex]::match($uninstallString,'\{(.*?\})')
}
elseif($modifyPath -match "^msiexec"){
$htProps.msiGUID = [regex]::match($modfiyPath,'\{(.*?\})')
}
New-Object PSObject -Property $htProps
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment