Created
September 18, 2023 15:00
-
-
Save junecastillote/563941b5f0e883d7486dcb155c541f84 to your computer and use it in GitHub Desktop.
PowerShell script to get installed apps using local or remote registry
This file contains 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
## ORIGINALLY FROM - https://theitbros.com/how-to-get-list-of-installed-programs-in-windows-10 | |
# Get-InstalledApps.ps1 | |
[CmdletBinding()] | |
param ( | |
[parameter()] | |
[switch]$Credential, | |
[parameter(ValueFromPipeline = $true)] | |
[String[]]$ComputerName = $env:COMPUTERNAME | |
) | |
begin { | |
$key = "SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\" | |
} | |
process { | |
$ComputerName | ForEach-Object { | |
$Comp = $_ | |
if (!$Credential) { | |
$reg = [microsoft.win32.registrykey]::OpenRemoteBaseKey('Localmachine', $Comp) | |
$regkey = $reg.OpenSubKey([regex]::Escape($key)) | |
$SubKeys = $regkey.GetSubKeyNames() | |
Foreach ($i in $SubKeys) { | |
$NewSubKey = [regex]::Escape($key) + "" + $i | |
$ReadUninstall = $reg.OpenSubKey($NewSubKey) | |
$DisplayName = $ReadUninstall.GetValue("DisplayName") | |
$Date = $ReadUninstall.GetValue("InstallDate") | |
$Publ = $ReadUninstall.GetValue("Publisher") | |
New-Object PsObject -Property @{"Name" = $DisplayName; "Date" = $Date; "Publisher" = $Publ; "Computer" = $Comp } | Where-Object { $_.Name } | |
} | |
} | |
else { | |
$Cred = Get-Credential | |
$connect = New-Object System.Management.ConnectionOptions | |
$connect.UserName = $Cred.GetNetworkCredential().UserName | |
$connect.Password = $Cred.GetNetworkCredential().Password | |
$scope = New-Object System.Management.ManagementScope("$Comprootdefault", $connect) | |
$path = New-Object System.Management.ManagementPath("StdRegProv") | |
$reg = New-Object System.Management.ManagementClass($scope, $path, $null) | |
$inputParams = $reg.GetMethodParameters("EnumKey") | |
$inputParams.sSubKeyName = $key | |
$outputParams = $reg.InvokeMethod("EnumKey", $inputParams, $null) | |
foreach ($i in $outputParams.sNames) { | |
$inputParams = $reg.GetMethodParameters("GetStringValue") | |
$inputParams.sSubKeyName = $key + $i | |
$temp = "DisplayName", "InstallDate", "Publisher" | ForEach-Object { | |
$inputParams.sValueName = $_ | |
$outputParams = $reg.InvokeMethod("GetStringValue", $inputParams, $null) | |
$outputParams.sValue | |
} | |
New-Object PsObject -Property @{"Name" = $temp[0]; "Date" = $temp[1]; "Publisher" = $temp[2]; "Computer" = $Comp } | Where-Object { $_.Name } | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment