dashboards011
dashboards011

Reputation: 13

Powershell Script to find the file from multiple servers and export to Excel

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

Answers (1)

HappyBob
HappyBob

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

Related Questions