更优雅地从计算机列表中复制目标文件

时间:2017-09-20 14:56:45

标签: powershell logging naturallyspeaking

我从前50台计算机收集日志,以分析名为Dragon的应用程序的用户信息,用于指示文本。我用来收集这些日志的脚本可能会好得多。有人愿意分享改进的建议吗?指出我正确的方向,我会做其余的事情。请找到下面粘贴的代码。

#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 个答案:

答案 0 :(得分:0)

您可以将命令组合在一起

获取内容| Foreach Line Run Copy-Item

RoboCopy来清理

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