Search code examples
powershellpowershell-remoting

How do I get a list of the servers as well as respective application and version of that very same app to be exported properly into excel?


With this script, I am able to find a specific application on a list of multiple remote devices and determine the version number of the application on their corresponding host system. This is outputted beautifully in the PS window. However, I am having trouble exporting the results properly into excel, that is, I want each property (Name, Version, PSComputerName) to be in a separate column vs all in one column. So far, I've tried the following

$list = Get-Content -Path C:\Users\bob\AppList.txt
$Servers = Get-Content -Path C:\Users\bob\ServerList.txt

foreach ($Serv in $Servers) {
    Get-WmiObject -Namespace ROOT\CIMV2 -Class Win32_Product -ComputerName $Serv |
        Select-Object -Property Name, Version, PSComputerName | 
        Where-Object -FilterScript { $_.Name -like "*$list*" } | 
        Export-Csv -Path C:\Users\bob\ServerListResults.csv
}

This resulted in simply just one device's information being extracted while every other cell was empty


Solution

  • I added -append at the very end! Thank you anyways!