Files
Samsara/powershell/Get-ServerSoftware.ps1

38 lines
2.0 KiB
PowerShell

function Read-SamsaraSoftwareEntries {
param($Result, $Uninstall, [string]$View)
foreach ($name in $Uninstall.GetSubKeyNames()) {
$entry = $null
try {
$entry = $Uninstall.OpenSubKey($name, $false)
if ($null -eq $entry) { throw 'Software entry not readable.' }
$display = [string]$entry.GetValue('DisplayName')
if ($display) {
$Result.data += [pscustomobject]@{ name = $display; publisher = [string]$entry.GetValue('Publisher')
version = [string]$entry.GetValue('DisplayVersion'); installation_date = [string]$entry.GetValue('InstallDate')
registry_view = $View }
}
} catch { Add-SamsaraError $Result $_ 'Machine software entry' }
finally { if ($entry) { $entry.Dispose() } }
}
}
function Get-SamsaraSoftware {
param($Result)
# Explicit registry views avoid 32-bit redirection and require no installer queries.
foreach ($view in @([Microsoft.Win32.RegistryView]::Registry64, [Microsoft.Win32.RegistryView]::Registry32)) {
Invoke-SamsaraRead $Result ('Machine software registry ' + [string]$view) {
$hive = $null; $uninstall = $null
try {
$hive = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine, $view)
$uninstall = $hive.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall', $false)
if ($null -eq $uninstall) { return }
Read-SamsaraSoftwareEntries $Result $uninstall ([string]$view)
} finally {
if ($uninstall) { $uninstall.Dispose() }
if ($hive) { $hive.Dispose() }
}
}
}
$Result.limitations += 'Machine uninstall registrations in both registry views only. Per-user, portable, container and unregistered software may be absent. Install dates are raw registry values and may be empty. No installer consistency checks are triggered.'
}