PowerShellで各フォルダーの合計サイズを確認するには、Get-ChildItemとMeasure-Objectコマンドレットを組み合わせて使用します。以下のスクリプトは、指定したディレクトリ内の各サブフォルダーの合計サイズを計算して表示します。
powershell
# 調べたいディレクトリのパスを指定します
$directoryPath = "C:\Path\To\Your\Folder"
# 各サブフォルダーの合計サイズを計算して表示
Get-ChildItem -Directory -Path $directoryPath | ForEach-Object {
$folderPath = $_.FullName
$folderSize = (Get-ChildItem -Path $folderPath -Recurse | Measure-Object -Property Length -Sum).Sum
[PSCustomObject]@{
フォルダー名 = $_.Name
サイズMB = [Math]::Round($folderSize / 1MB, 2)
}
} | Sort-Object サイズMB -Descending | Format-Table -AutoSize
スクリプトの解説