Skip to content

Instantly share code, notes, and snippets.

@aaronparker
Last active September 1, 2025 23:16
Show Gist options
  • Select an option

  • Save aaronparker/5d54887eec8e316ab10222304124751c to your computer and use it in GitHub Desktop.

Select an option

Save aaronparker/5d54887eec8e316ab10222304124751c to your computer and use it in GitHub Desktop.
List installed software, gather uninstall string and format into a usable object
function Get-InstalledSoftware {
$PropertyNames = "DisplayName", "DisplayVersion", "Publisher", "UninstallString", "PSPath", "WindowsInstaller",
"InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize", "SystemComponent"
("HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*",
"HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*") | `
ForEach-Object {
Get-ItemProperty -Path $_ -Name $PropertyNames -ErrorAction "SilentlyContinue" | `
. { process { if ($null -ne $_.DisplayName) { $_ } } } | `
Select-Object -Property @{n = "Name"; e = { $_.DisplayName } }, @{n = "Version"; e = { $_.DisplayVersion } }, "Publisher",
"UninstallString", @{n = "RegistryPath"; e = { $_.PSPath -replace "Microsoft.PowerShell.Core\\Registry::", "" } },
"PSChildName", "WindowsInstaller", "InstallDate", "InstallSource", "HelpLink", "Language", "EstimatedSize" | `
Sort-Object -Property "Name", "Publisher"
}
}
function ConvertTo-UninstallCommand {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[System.String] $UninstallString
)
begin {
$regex = '(?i)"?([A-Z]:\\[^"]*?\.exe|[A-Za-z0-9._-]+\.exe)"?\s*((?:\S+\s*)*)'
}
process {
if ($UninstallString -match $regex) {
$Exe = $Matches[1]
$Arguments = $Matches[2]
[PSCustomObject]@{
FilePath = if ($Exe -match "msiexec.exe") { "$Env:SystemRoot\System32\msiexec.exe" } else { $Exe }
ArgumentList = ($Arguments -replace '\s+', ' ').Trim()
}
}
else {
return $null
}
}
}
Get-InstalledSoftware | ForEach-Object {
if ($null -ne $_.UninstallString) {
[PSCustomObject]@{
Name = $_.Name
Version = $_.Version
UninstallCommand = (ConvertTo-UninstallCommand -UninstallString $_.UninstallString)
}
}
}
@aaronparker
Copy link
Author

Example output:

uninstallstring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment