Last active
September 1, 2025 23:16
-
-
Save aaronparker/5d54887eec8e316ab10222304124751c to your computer and use it in GitHub Desktop.
List installed software, gather uninstall string and format into a usable object
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | |
| } | |
| } | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output: