Skip to content

Instantly share code, notes, and snippets.

@glektarssza
Last active May 13, 2025 20:18
Show Gist options
  • Save glektarssza/158f36af73a8919948eb4b4522f20016 to your computer and use it in GitHub Desktop.
Save glektarssza/158f36af73a8919948eb4b4522f20016 to your computer and use it in GitHub Desktop.
Get-SoftwareList PowerShell Cmdlet
<#
.SYNOPSIS
Get a list of software installed on the system from the Windows Registry.
#>
function Get-SoftwareList {
[CmdletBinding()]
param(
# The name of the software items to include in the list. Wild cards are
# acceptable. Inclusions are applied after exclusions and before
# filters.
[String[]]
$Include = @(),
# The name of the software items to exclude from the list. Wild cards
# are acceptable. Exclusions are applied before inclusions and filters.
[String[]]
$Exclude = @(),
# The names of the software items to filter the list for. Wild cards are
# acceptable. Filters are applied after inclusions and exclusions.
[String[]]
$Filter = @(),
# The property to use for including, excluding, and filtering items.
[String]
$Property = "DisplayName"
)
$local:excludePatterns = ($Exclude | ForEach-Object {([WildcardPattern]::Get($_, [System.Management.Automation.WildcardOptions]::Compiled))});
$local:includePatterns = ($Include | ForEach-Object {([WildcardPattern]::Get($_, [System.Management.Automation.WildcardOptions]::Compiled))});
$local:filterPatterns = ($Filter | ForEach-Object {([WildcardPattern]::Get($_, [System.Management.Automation.WildcardOptions]::Compiled))});
$local:softwareList = (Get-ItemProperty -Path HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*);
$local:softwareList += (Get-ItemProperty -Path HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*);
return $local:softwareList | ForEach-Object {
if (($null -eq $local:excludePatterns) -or ($local:excludePatterns.Count -eq 0)) {
return $_;
}
ForEach ($local:pattern in $local:excludePatterns) {
if ($local:pattern.IsMatch(($_ | Select-Object -ExpandProperty $Property -ErrorAction SilentlyContinue))) {
continue;
}
}
return $_;
} | ForEach-Object {
if (($null -eq $local:includePatterns) -or ($local:includePatterns.Count -eq 0)) {
return $_;
}
ForEach ($local:pattern in $local:includePatterns) {
if ($local:pattern.IsMatch(($_ | Select-Object -ExpandProperty $Property -ErrorAction SilentlyContinue))) {
return $_;
}
}
} | ForEach-Object {
if (($null -eq $local:filterPatterns) -or ($local:filterPatterns.Count -eq 0)) {
return $_;
}
ForEach ($local:pattern in $local:filterPatterns) {
if ($local:pattern.IsMatch(($_ | Select-Object -ExpandProperty $Property -ErrorAction SilentlyContinue))) {
return $_;
}
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment