Get-Content $dir\computers.txt | Foreach-Object {
Get-HotFix -ComputerName $_ | Export-Csv -Path "$dir\$($_)_HotFixData.csv" -notype
}
How to output separate CSV files per server name
-
29-11-2021 - |
Question
I want my PowerShell script to go out to remote servers, gather hotfix data, and export that data to Excel for each server or one Excel sheet per server.
Currently when I run the script it does go out to each server listed in a .txt
file and gathers the hotfix data. But it exports that data to one Excel file with a name of all the servers. It's a very long name!
Here's the script:
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
$Server_Name = Get-Content $dir\computers.txt
Get-HotFix -computername $Server_Name | Export-Csv -Path "$dir\$Server_Name HotFixData.csv" -notype
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow