I'm trying to get a list of installed programs off a group of remote servers. I'm able to get the program name but not return the system name. Below is my script.
$computerfile = get-content "D:\Users\Admin\Docs\PrimaryServers.txt"
ForEach ($computer in $computerfile) {
Get-WmiObject Win32_Product -ComputerName $computer |
Select-Object SystemName,Name,Version,PackageName,Installdate,Vendor |
Format-Table -AutoSize
}
Below is my output
First, -ComputerName
can take an array of names so by looping you are going to increase the time because the loop will be in serial where utilizing the array for computername will be in parallel.
Second, it's best practice to use the CIM cmdlets in place of the WMI cmdlets. They operate over WSMAN by default and are easier to work with.
Third, Win32_Product forces a consistency check so reading the Uninstall registry keys is usually superior.
Lastly, SystemName
isn't a property name that is returned by Get-WMIObject
. PSComputerName
is the property you are looking for and you can make a Calculated Property from it.
$computerfile = get-content "D:\Users\Admin\Docs\PrimaryServers.txt"
Get-CimInstance Win32_Product -ComputerName $Computerfile |
Select-Object @{n=SystemName;e={$_.PSComputerName}},Name,Version,PackageName,Installdate,Vendor |
Format-Table -AutoSize