Last active
February 14, 2016 19:27
-
-
Save DBremen/2225b030b75388ad53c7 to your computer and use it in GitHub Desktop.
Retrieve Uninstall information for software packages from the registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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