22
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellで特定のフォルダ以下のフォルダの容量チェック

Last updated at Posted at 2014-11-29

カレントフォルダ以下の容量をチェック

  • ファイル単位じゃなくフォルダ単位で容量一覧がほしい
powershell
Get-ChildItem `
    | Select-Object Name, @{ name = "Size"; expression = { `
        [math]::round((Get-ChildItem $_.FullName -Recurse -Force `
            | Measure-Object Length -Sum `
        ).Sum /1MB ) `
} }
  • /1MBでバイト単位のデータをMB単位に変換

追記(18/11/22)

  • 任意のフォルダ配下の、一定容量を越えるフォルダやファイルのパス・容量の一覧がほしい
powershell
function getFuckinHeavyWeightData($path) {
    $children = Get-ChildItem $path `
        | Select-Object `
            Name, `
            @{ name = "Size"; expression = { `
                [math]::round((Get-ChildItem $_.FullName -Recurse -Force `
                    | Measure-Object Length -Sum `
             ).Sum /1MB ) `
            } }, `
            FullName `
        | Where-Object {$_.Size -gt 100}


    foreach($e in $children) {
        if ($e.Size -gt 100) { # 100MB以上をチェック対象とする
            echo ($e.FullName + ',' +  $e.Size)
            if (Test-Path $e.FullName -PathType container) {
                cd $e.FullName
                getFuckinHeavyWeightData($e.FullName)
            }
        }
    }
}
$root = "C:\apps\"
getFuckinHeavyWeightData($root)
22
26
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
22
26

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?