Another approach is to use the Invoke-Command
where it automatically extends the result with the PSComputerName
column
First build up the script blocks to use as query
Block 1 is my approach for both x32 and x64 implementations. Consider this as an alternative because I has some issues with the proposed implementation.
$block1={
# Query x64 bit applications
$queryPath="HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*"
Get-ItemProperty $queryPath | Select-Object -Property DisplayName, Publisher, InstallDate, DisplayVersion
# Query x32 bit applications
$queryPath="HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*"
Get-ItemProperty $queryPath | Select-Object -Property DisplayName, Publisher, InstallDate, DisplayVersion
}
Block 2 is the proposed approach on this question
$block2={
Get-CimInstance Win32_Product | Select-Object Name,Version,PackageName,Installdate,Vendor
}
For either $block1
or $block2
execute remotely on a server list
Invoke-Command -ComputerName $computernames -ScriptBlock $block1
And one record looks like this
DisplayName : Microsoft Visual C++ 2013 x86 Additional Runtime - 12.0.21005
Publisher : Microsoft Corporation
InstallDate : 20161202
DisplayVersion : 12.0.21005
PSComputerName : MECDEVAPP01
RunspaceId : 4b8cc747-da25-4c6e-b108-0ca3138c0335