Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用Powershell递归处理目录统计信息_Powershell_Recursion_Directory_Filesize - Fatal编程技术网

使用Powershell递归处理目录统计信息

使用Powershell递归处理目录统计信息,powershell,recursion,directory,filesize,Powershell,Recursion,Directory,Filesize,我目前正在使用我编写的脚本,对目录递归使用Logparser查询,以生成以下输出: QTY TOT KB AVRG KB MAXM KB MINM KB ------- --------- ------- ------- ------- 3173881 175101609 55 85373 0 我希望使用powershell复制此信息,以使收集此信息更加方便。不需要安装/复制logparser 我搜索并试图操纵我找到的示例,但无法完全理解其结构 以下是我得到的最接近

我目前正在使用我编写的脚本,对目录递归使用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
有什么建议吗?如果可能的话,我更愿意使用一行命令。

度量对象只执行它被告知的操作,因此如果您只使用-Sum,那么您只获得Sum

Get-ChildItem -Recurse -File | Measure-Object -Sum -Average -Maximum -Minimum -Property Length | Select Count, Average, Sum, Maximum, Minimum

获取子项非常慢;使用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
机器人复制选项包括:

/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分割输出,删除文件名和robocy状态,只保留大小,measure对象计算结果,format表将其转换为外观更好的表输出