Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Created July 6, 2024 18:04
Show Gist options
  • Save DJStompZone/0bdb768b782261ed40783b2b8f8d47c3 to your computer and use it in GitHub Desktop.
Save DJStompZone/0bdb768b782261ed40783b2b8f8d47c3 to your computer and use it in GitHub Desktop.
Powershell script to get GUIDs for all installed software
function Get-InstalledSoftware {
<#
.SYNOPSIS
Retrieves a list of all software installed on the system and their corresponding 128-bit Windows GUID.
.PARAMETER Name
The software title you would like to limit the query to.
.PARAMETER Format
The output format for the retrieved software list. Can be 'JSON' or 'XML'.
.EXAMPLE
Get-InstalledSoftware
This example retrieves all software installed on the local computer and formats it as JSON.
.EXAMPLE
Get-InstalledSoftware -Name "Ubuntu" -Format XML
This example retrieves all software installed on the local computer with a name matching "*Ubuntu*" and formats it as XML.
.NOTES
Author: DJ Stomp <https://github.com/DJStompZone>
Date: 07/06/2024
#>
[OutputType([System.Management.Automation.PSObject])]
[CmdletBinding()]
param (
[Parameter()]
[ValidateNotNullOrEmpty()]
[string]$Name,
[Parameter()]
[ValidateSet("JSON", "XML")]
[string]$Format = "JSON"
)
$textInfo = (Get-Culture).TextInfo
$UninstallKeys = "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall", "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
$null = New-PSDrive -Name HKU -PSProvider Registry -Root Registry::HKEY_USERS
$UninstallKeys += Get-ChildItem HKU: -ErrorAction SilentlyContinue | Where-Object { $_.Name -match 'S-\d-\d+-(\d+-){1,14}\d+$' } | ForEach-Object { "HKU:\$($_.PSChildName)\Software\Microsoft\Windows\CurrentVersion\Uninstall" }
$installedSoftware = @()
if (-not $UninstallKeys) {
Write-Verbose -Message 'No software registry keys found'
} else {
foreach ($UninstallKey in $UninstallKeys) {
if ($PSBoundParameters.ContainsKey('Name')) {
$WhereBlock = { ($_.PSChildName -match '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$') -and ($_.GetValue('DisplayName') -like "$Name*") }
} else {
$WhereBlock = { ($_.PSChildName -match '^{[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}}$') -and ($_.GetValue('DisplayName')) }
}
$gciParams = @{
Path = $UninstallKey
ErrorAction = 'SilentlyContinue'
}
$selectProperties = @(
@{n='GUID'; e={$_.PSChildName}},
@{n='Name'; e={$_.GetValue('DisplayName')}}
)
$installedSoftware += Get-ChildItem @gciParams | Where $WhereBlock | Select-Object -Property $selectProperties
}
}
foreach ($app in (Get-AppxPackage)) {
if (-not $PSBoundParameters.ContainsKey('Name') -or $app.Name -like "*$Name*") {
$manifest = Get-AppxPackageManifest $app
if ($manifest.Package.PhoneIdentity.PhoneProductId) {
$pkgName = $app.name.replace($app.name.split('(.)')[0]+'.', '')
$appInfo = [PSCustomObject]@{
GUID = '{' + $textInfo.toUpper($manifest.Package.PhoneIdentity.PhoneProductId) + '}'
appName = $pkgName
appId = $app.name
appAliases = $manifest.Package.Applications.Application.Id
}
$installedSoftware += $appInfo
}
}
}
if ($Format -eq "JSON") {
$installedSoftware | ConvertTo-Json -Depth 3
} elseif ($Format -eq "XML") {
$installedSoftware | ConvertTo-Xml -NoTypeInformation
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment