欢迎各位兄弟 发布技术文章
这里的技术是共享的
最好以管理员身份运行,否则可能会报什么什么访问被拒绝之类的错
用一行命令 powershell 分析当前路径下 各个文件夹 大小 ,,,以方便人阅读的方式显示,,,按从大到小排序
Get-ChildItem -Directory | ForEach-Object {
$sizeBytes = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum
if ($sizeBytes -ne $null) {
$sizeMB = [math]::round($sizeBytes / 1MB, 2) # Convert to MB
if ($sizeMB -ge 1024) {
$sizeGB = [math]::round($sizeMB / 1024, 2) # Convert to GB
$sizeDisplay = "$sizeGB GB"
} elseif ($sizeMB -ge 1) {
$sizeDisplay = "$sizeMB MB"
} else {
$sizeKB = [math]::round($sizeBytes / 1KB, 2) # Convert to KB
$sizeDisplay = "$sizeKB KB"
}
[PSCustomObject]@{
Directory = $_.FullName
Size = $sizeDisplay
}
}
} | Sort-Object -Property {
$size = $_.Size -replace ' GB', '' -replace ' MB', '' -replace ' KB', ''
if ($_.Size -like '*GB') { [double]$size * 1024 * 1024 }
elseif ($_.Size -like '*MB') { [double]$size * 1024 }
else { [double]$size }
} -Descending | Format-Table -AutoSize # ok ook
Get-ChildItem -Directory | ForEach-Object {
$size = (Get-ChildItem $_.FullName -Recurse -File -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1MB
if ($size) {
[PSCustomObject]@{ Directory = $_.FullName; SizeMB = [math]::round($size, 2) }
}
} | Where-Object { $_.SizeMB -ne $null } | Sort-Object -Property SizeMB -Descending | Format-Table -AutoSize # ok
用一行命令 powershell 分析当前路径下 各个文件夹 大小
Get-ChildItem -Directory | ForEach-Object { [PSCustomObject]@{ Directory = $_.FullName; SizeMB = [math]::round((Get-ChildItem $_.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB, 2) } } | Sort-Object -Property SizeMB -Descending | Format-Table -AutoSize # ok
用一行命令 powershell 分析当前路径下 各个文件夹 大小
Get-ChildItem -Path . -Recurse -Directory | ForEach-Object { $_.FullName, (Get-ChildItem -Path $_.FullName -Recurse -File | Measure-Object -Property Length -Sum).Sum / 1MB } # not ok
用一行命令 powershell 分析当前路径下 各个文件夹 大小
Get-ChildItem -Directory | % { "$($_.FullName): $(Get-ChildItem $_.FullName -Recurse | Measure-Object -Sum Length).Sum" } # not ok