Skip to content

Instantly share code, notes, and snippets.

@DBremen
Created February 14, 2016 19:30
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/b1f581769ddb515e6392 to your computer and use it in GitHub Desktop.
Save DBremen/b1f581769ddb515e6392 to your computer and use it in GitHub Desktop.
Retrieve Uninstall information for software packages via Get-Package PowerShell v5
#requires -Version 5
Get-Package | foreach{
$attributes = $_.meta.attributes
$htProps = [Ordered]@{msiGUID=''}
for ($i=0;$i -lt $attributes.keys.count;$i++){
$htProps.Add($attributes.keys[$i].LocalName,$attributes.values[$i])
}
if ($htProps.Contains('DisplayName')){
$uninstallString = $htProps.UninstallString
$modifyPath = $htProps.ModifyPath
if($uninstallString -match "^msiexec"){
$htProps.msiGUID = [regex]::match($uninstallString,'\{(.*?\})')
}
elseif($modifyPath -match "^msiexec"){
$htProps.msiGUID = [regex]::match($modfiyPath,'\{(.*?\})')
}
New-Object PSObject -Property $htProps #| select DisplayName, UninstallString, msiGUID, InstallLocation, Version
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment