private/_GetSoftwareInfo.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
function _GetSoftwareInfo {
    [cmdletbinding()]
    Param(
        [System.Management.Automation.Runspaces.PSSession]$PSSession
    )
    Write-Verbose "[$($PSSession.ComputerName)] - Gathering Software information"
    $Programs = Invoke-Command -Session $PSSession -ScriptBlock {
        $Keys = @('HKLM:\SOFTWARE\Microsoft\Windows\Currentversion\Uninstall\*', 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\Currentversion\Uninstall\*')
        Get-ItemProperty -Path $Keys -ErrorAction SilentlyContinue
    }
    foreach ($Program in $Programs) {
        if ($Program.DisplayName -AND $Program.DisplayName -notmatch '^Update for|rollup|^Security Update|^Service Pack|^HotFix') {
            [PSCustomObject]@{
                PSTypeName      = 'PSP.Inventory.Software'
                ComputerName    = $PSSession.ComputerName
                DisplayName     = $Program.DisplayName
                Version         = $Program.DisplayVersion
                InstallDate     = if ($Program.InstallDate) {try {[datetime]::ParseExact($($Program.InstallDate), 'yyyyMMdd', [System.Globalization.CultureInfo]::InvariantCulture)}catch{$null}} else {$null}
                Publisher       = $Program.Publisher
                UninstallString = $Program.UninstallString
                InstallLocation = $Program.InstallLocation
                InstallSource   = $Program.InstallSource
                HelpLink        = $Program.HelpLink
                EstimatedSize   = [math]::Round(($Program.EstimatedSize * 1024) / 1MB, 2)
                InventoryDate   = (Get-Date)
            }
        }
    }
}