Skip to content

Instantly share code, notes, and snippets.

@mark05e
Created February 29, 2020 12:09
Show Gist options
  • Save mark05e/e9ff8067211caa51ca4556b161b0f0a7 to your computer and use it in GitHub Desktop.
Save mark05e/e9ff8067211caa51ca4556b161b0f0a7 to your computer and use it in GitHub Desktop.
Get list of all installed applications from registry in 32- or 64-bit Powershell

getInstalledAppsFromRegistry.ps1

Source: Technet Script Center

Example:

.\getInstalledAppsFromRegistry.ps1
$apps = Get-InstalledAppsFromRegistry
$apps | where {$_.DisplayName -like "*Firefox*"}

You will get results like:

Publisher        : Mozilla
DisplayName      : Mozilla Firefox 51.0.1 (x86 en-US)
NoModify         : 1
UninstallString  : "C:\Program Files (x86)\Mozilla Firefox\uninstall\helper.exe"
APP_GUID         : Mozilla Firefox 51.0.1 (x86 en-US)
Comments         : Mozilla Firefox 51.0.1 (x86 en-US)
DisplayVersion   : 51.0.1
URLInfoAbout     : https://www.mozilla.org
APP_Architecture : 32
URLUpdateInfo    : https://www.mozilla.org/firefox/51.0.1/releasenotes
NoRepair         : 1
InstallLocation  : C:\Program Files (x86)\Mozilla Firefox
DisplayIcon      : C:\Program Files (x86)\Mozilla Firefox\firefox.exe,0
EstimatedSize    : 94368
HelpLink         : https://support.mozilla.org
# getInstalledAppsFromRegistry.ps1
# ref: https://gallery.technet.microsoft.com/scriptcenter/Get-list-of-installed-36a17e1b
function Get-InstalledAppsFromRegistry
{
$scriptBlock={
#this function gets all properties from registry
#It doesn't fail if a property value is corrupted
function read-AppPropertiesToObj{
param($Application, $Architecture)
$prop = @{
APP_Architecture = $Architecture
APP_GUID = $Application.PSChildName
}
#for PS 2.0 compatibility
$itemslist = @($Application | select -ExpandProperty Property)
foreach ($item in $itemslist)
{
#if value is corrupted, get-itemproperty function fails
try
{
$prop.$item = $Application | Get-ItemProperty -name $item | select -ExpandProperty $item
}
catch
{
$prop.$item = '(invalid value)'
}
}
$result = New-Object psobject -Property $prop
return $result
}#function
$apps = @()
$results = @()
if (Test-Path 'HKLM:\SOFTWARE\Wow6432Node\microsoft\Windows\CurrentVersion\Uninstall')
{
#
#"64 bit system, 32 bit node"
$apps = Get-ChildItem 'HKLM:\SOFTWARE\Wow6432Node\microsoft\Windows\CurrentVersion\Uninstall'
foreach ($app in $apps)
{
$results += read-AppPropertiesToObj -Application $app -Architecture 32
}
#64 bit system, 64 bit node
$apps = Get-ChildItem 'HKLM:\SOFTWARE\microsoft\Windows\CurrentVersion\Uninstall'
foreach ($app in $apps)
{
$results += read-AppPropertiesToObj -Application $app -Architecture 64
}
}
else
{
#32 bit system, 32 bit node
$apps = Get-ChildItem 'HKLM:\SOFTWARE\microsoft\Windows\CurrentVersion\Uninstall'
foreach ($app in $apps)
{
$results += read-AppPropertiesToObj -Application $app -Architecture 32
}
}#if else
return $results | sort DisplayName
}#scriptblock
#determine OS architecture and path to the native powershell.exe
#-----32 bit process running on a 64 bit machine
if (([intptr]::size -eq 4) -and (test-path env:\PROCESSOR_ARCHITEW6432))
{
$PsExePath = "C:\windows\sysnative\WindowsPowerShell\v1.0\powershell.exe"
}
#-----64 bit process running on a 64 bit machine
elseif (([intptr]::size -eq 8) -and !(test-path env:\PROCESSOR_ARCHITEW6432))
{
$PsExePath = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
}
#-----32 bit process running on a 32 bit machine
else
{
$PsExePath = "C:\windows\system32\WindowsPowerShell\v1.0\powershell.exe"
}
#execute command
$tmp = & $PsExePath $scriptBlock
#return results
return $tmp
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment