Reputation: 13
So far I have created a PowerShell script to find the specific files from multiple servers and dump the output to excel file.
For some reason my script only dumps the output for 1 server (last one to the list) out of 50. Not sure what I'm missing.
$server = get-content "C:\temp\servers.txt"
Foreach ($srv in $server)
{
Get-ChildItem -Path "\\$srv\d$\temp\" -include "java_pid*" -Recurse -ErrorAction silentlycontinue | export-csv c:\temp\results.csv
}
When run the script it will go thru all the servers and dump the export to excel file.
Upvotes: 0
Views: 1183
Reputation: 146
Use the -Append tag this will append each of the server results pipeline into one long results.csv. Right now you are overwriting the output csv for each server.
$server = get-content "C:\temp\servers.txt" Foreach ($srv in $server) { Get-ChildItem -Path "\$srv\d$\temp\" -include "java_pid*" -Recurse -ErrorAction silentlycontinue | export-csv c:\temp\results.csv -Append}
Upvotes: 1