copy target files from list of computers more elegantly

199 Views Asked by At

I collect logs from the top 50 computers to analyze user information of an application called Dragon, used to dictatate text. The script I use to collect these logs I think could be much better. Anyone care to share suggestion for improvment? Point me in the right direction and I will do the rest. Please find the code pasted below.

#copying ALL directories from c:\User\ recursively, and as many of the log files #as it finds.  Copies perhaps 100-1000 empty directories for every log file it finds.


$server_names = Get-Content "C:\powershell\Dragonlog\Log Grab\sept915920.txt"
Foreach ($server in $server_names){
Copy-Item \\$server\c$\Users C:\dgnlogs\top50915920\$Server -filter dragon.log -Recurse 

}

#robocopy to remove redundant empty directories. 

robocopy C:\dgnlogs\top50915920 C:\splunkdragonlogs\top50915920 /s /move
1

There are 1 best solutions below

0
On

You can pipe together commands

Get Content | Foreach Line Run Copy-Item

RoboCopy to Clean Up

Get-Content "C:\powershell\Dragonlog\Log Grab\sept915920.txt" | Copy-Item \\$_\c$\Users C:\dgnlogs\top50915920\$_ -filter dragon.log -Recurse
robocopy C:\dgnlogs\top50915920 C:\splunkdragonlogs\top50915920 /s /move