简体   繁体   English

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

[英]Process directory statistics recursively using Powershell

I am currently using a script I wrote to use a Logparser query against a directory recursively to produce the following output: 我当前正在使用编写的脚本来递归地对目录使用Logparser查询,以产生以下输出:

QTY     TOT KB    AVRG KB MAXM KB MINM KB
------- --------- ------- ------- -------
3173881 175101609 55      85373   0

I would like to reproduce this using powershell in an attempt to make collecting this information more portable. 我想使用powershell来重现此信息,以使收集此信息的操作更加方便。 (Not needing to install / copy logparser) (不需要安装/复制logparser)

I searched and attempted to manipulate what examples I have found but can't quite get the structure down. 我搜索并尝试操纵发现的示例,但无法完全理解该示例。

Here is the closest I have gotten: 这是我最近得到的:

Get-ChildItem -Recurse | Measure-Object -sum Length | Select-Object Count,Average,Sum

This returns: 返回:

Count Average                                                                     Sum
----- -------                                                                     ---
44663                                                                     40861708776

Any suggestions? 有什么建议么? I would prefer to stick to a "one line" command if possible. 如果可能,我希望坚持使用“一行”命令。

Measure-Object仅执行其所要执行的操作,因此,如果仅使用-Sum ,则只会得到Sum。

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

Get-ChildItem is pretty slow; Get-ChildItem相当慢; what about using RoboCopy to list the folder contents? 使用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

Which goes to a one-liner: 这是单线的:

robocopy $Folder $Folder /S /L /BYTES /NJH /NJS /NDL /V |%{(-split $_)[1]}|measure -a -s -ma -mi | ft

Robocopy options are: 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)

Then the ForEach splits the output to drop the filename and robocopy status and just keep the size, and measure-object calculates the results, and format-table turns it into a nicer looking table output. 然后,ForEach将输出拆分以删除文件名和robocopy状态并仅保留大小,然后measure-object计算结果,而format-table将其转换为外观更好的表输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在目录上以递归方式使用PowerShell运行简单命令 - Run a simple command using PowerShell recursively on a directory 使用Powershell递归搜索目录以查找仅包含零的文件 - Using Powershell to recursively search directory for files that only contain zeros Powershell 递归写入同目录 - Powershell Recursively writing to the same directory 在 ADLS Gen 1 中递归报告文件夹统计信息 - CLI 或 Powershell - Recursively Report Folder statistics in ADLS Gen 1 - CLI or Powershell 使用Powershell进行统计CSV - Making statistics CSV using Powershell 在目录中递归列出不需要的文件 - Powershell - Listing unwanted files recursively in a directory - Powershell 如何使用 PowerShell 2.0 递归删除整个目录? - How to recursively delete an entire directory with PowerShell 2.0? Powershell以递归方式获取目录中文件的过滤列表 - Powershell Recursively getting filtered list of files in directory 递归复制 powershell 中目录和子目录的内容 - Recursively copy contents of directory and subdirectories in powershell 如何将项目动态添加到 PowerShell ArrayList 并使用运行空间池递归处理它们? - How to dynamically add items to a PowerShell ArrayList and process them recursively using Runspace pool?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM