如何解决我可以让 robocopy 日志文件只显示一行摘要和日期吗?而不是有多个列?谢谢
到目前为止,我的代码仅用于显示 robocopy 的摘要。我可以让这个非常短和 1 行吗?就像一行显示复制的总大小、日期以及它是否成功或类似的东西。谢谢
/Z /e /xx /W:5 /NFL /NDL /NJH /nc /np /unilog+:$Logfile
这是输出:
Total Copied Skipped Mismatch FAILED Extras
Dirs : 1 0 0 0 0 0
Files : 10 1 9 0 0 0
Bytes : 1.009 g 102.79 m 931.15 m 0 0 0
Times : 0:00:06 0:00:06 0:00:00 0:00:00
Speed : 15897359 Bytes/sec.
Speed : 909.654 MegaBytes/min.
Ended : Thursday,April 29,2021 11:24:08 AM
解决方法
使用一点 Select-String、Trim 和 Split。
Clear-Host
#Next line for testing only you can delete since you already have it defined!
$LogFile = "G:\BEKDocs\Batch\BackupTasks\RoboCopyNAS.log"
$Log = Get-Content -Path "$LogFile"
$Bytes = $($Log | Select-String -Pattern "Bytes :" -SimpleMatch).Line.Trim(" ")
$DT = $($Log | Select-String -Pattern "Ended :" -SimpleMatch).Line.Trim(" ")
$Parts = $Bytes.Split(" ")
$Bytes = $Parts[3] + $Parts[4]
"Bytes Copied: $Bytes on $($DT.Trim('Ended :'))"
结果:
Bytes Copied: 27.493g on Thursday,April 29,2021 6:15:20 PM
HTH
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。