Let C:\ComputerList.txt
be a list of computers with one computer name on each line like:
COMPUTER1
COMPUTER2
COMPUTER3
COMPUTER4
So, here's how I would do it:
$ComputerListFile = 'C:\ComputerList.txt';
$OutputFile = 'C:\VMWareSoftwareReport.csv';
#Variable for the report with header
$Report = @();
$Report += '"ComputerName","SoftwareName","SoftwareVersion"';
#Get the list of computers
$ComputerList = Get-Content $ComputerListFile;
$ComputerList | ForEach-Object {
$ComputerName = $_;
#Ping the target to see if it's there
If ((Get-WmiObject Win32_PingStatus -Filter "Address='$ComputerName' AND Timeout=1000").StatusCode -eq 0) {
#Get the list of software
$vmWareSoftware = Get-WmiObject -Query "SELECT Name, Version FROM Win32_Product WHERE Name LIKE '%vmWare%'" -ComputerName $ComputerName | Sort-Object -Property Name;
$vmWareSoftware | ForEach-Object {
#Format the results, escape any double quotes, and add them to the report
$SoftwareName = $_.Name.Replace('"','""');
$SoftwareVersion = $_.Version.Replace('"','""');
$Report += '"{0}","{1}","{2}"' -f $ComputerName, $SoftwareName, $SoftwareVersion;
}
}
}
#Write the report file, overwriting if needed
Set-Content -Path $OutputFile -Value $Report -Force;
You might want to use Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*
as @expirat001 mentions, but Get-ItemProperty
can't target remote computers. It also may not be a complete listing. For that matter, Win32_Product
may not be complete, either. There's no comprehensive way to find all installed software in Windows.
Note also that Out-File
by default will overwrite, not append. You have to specify the -Append
switch, or you'd just get the one computer in the file.