[英]Process directory statistics recursively using Powershell
我當前正在使用編寫的腳本來遞歸地對目錄使用Logparser查詢,以產生以下輸出:
QTY TOT KB AVRG KB MAXM KB MINM KB
------- --------- ------- ------- -------
3173881 175101609 55 85373 0
我想使用powershell來重現此信息,以使收集此信息的操作更加方便。 (不需要安裝/復制logparser)
我搜索並嘗試操縱發現的示例,但無法完全理解該示例。
這是我最近得到的:
Get-ChildItem -Recurse | Measure-Object -sum Length | Select-Object Count,Average,Sum
返回:
Count Average Sum
----- ------- ---
44663 40861708776
有什么建議么? 如果可能,我希望堅持使用“一行”命令。
Measure-Object
僅執行其所要執行的操作,因此,如果僅使用-Sum
,則只會得到Sum。
Get-ChildItem -Recurse -File | Measure-Object -Sum -Average -Maximum -Minimum -Property Length | Select Count, Average, Sum, Maximum, Minimum
Get-ChildItem相當慢; 使用RoboCopy列出文件夾內容怎么辦?
$Folder = "D:\Downloads"
robocopy $Folder $Folder /S /L /BYTES /NJH /NJS /NDL /V |
ForEach-Object { (-split $_)[1] } |
Measure-Object -Maximum -Minimum -Sum -Average |
Format-Table
這是單線的:
robocopy $Folder $Folder /S /L /BYTES /NJH /NJS /NDL /V |%{(-split $_)[1]}|measure -a -s -ma -mi | ft
Robocopy選項包括:
/S - subdirectories (excluding empty ones)
/L - list files, don't do any copying or moving
/BYTES - show sizes in bytes, with no commas or anything
/NJH and /NJS - no header and summary lines in the output
/NDL - don't list directories
/V - verbose (do list individual files and their sizes)
然后,ForEach將輸出拆分以刪除文件名和robocopy狀態並僅保留大小,然后measure-object計算結果,而format-table將其轉換為外觀更好的表輸出。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.