我是 Powershell 新手,我尝试在网上寻找问题的解决方案,但似乎找不到。基本上我需要写一些东西,让 powershell 浏览所有驱动器和目录以找到以下内容:
文件总数(不包括文件夹)、最大文件大小、平均文件大小、总文件大小
这是我到目前为止所写的:
$source = "get-psdrive"
#attempt at looking through all drives/directories which didn't work
foreach($a in $source) {
#counts files in given directory
Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue -Force |
Measure-Object |
ForEach-Object { $_.Count }
#select largest file in given directory
Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue -Force |
Sort-Object Length -Descending |
Select-Object -First 1
#get average file size in a given directory
Get-ChildItem -Recurse -File -ErrorAction SilentlyContinue -Force |
Measure-Object -Property Length -Average …Run Code Online (Sandbox Code Playgroud)