Skip to content

Instantly share code, notes, and snippets.

@m4ss1m0g
Last active May 18, 2023 18:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4ss1m0g/3b2b0edd8d5eb73424cbf247265e0bb0 to your computer and use it in GitHub Desktop.
Save m4ss1m0g/3b2b0edd8d5eb73424cbf247265e0bb0 to your computer and use it in GitHub Desktop.
Lists all installed software, including any that is not visible with PowerShell
function Get-Installed {
[CmdletBinding()]
param (
# The name of the software
[Parameter(Mandatory = $true)]
[string] $Name
)
begin {
$PATHS = @(
"HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
)
}
process {
$installed = $null
ForEach ($path in $PATHS) {
$installed += Get-ChildItem -Path $path |
ForEach-Object { Get-ItemProperty $_.PSPath } |
Where-Object { $null -ne $_.DisplayName -and $_.DisplayName.Contains($Name) } |
Select-Object DisplayName, DisplayVersion, PSChildName |
Sort-Object -Property DisplayName
}
$installed
}
end {
}
}
function Remove-Installed {
[CmdletBinding()]
param (
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
$Guid
)
process {
Write-Verbose "Removing $Guid"
$a = "/x " + $Guid
Start-Process msiexec -Wait -ArgumentList $a
}
}
# Examples
#
# Get ALL software containing (case-SENSITIVE) .NET
# Get-Installed -Name .NET
#
# Get ALL software containing (case-SENSITIVE) .NET AND 3.1.10
# Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")}
#
# Get ALL software containing (case-SENSITIVE) .NET AND 3.1.10 AND Remove that software
# Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")} | Select -Expand PsChildName | Remove-Installed
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment