0
1

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 3 years have passed since last update.

フォルダ容量測定powershell

Last updated at Posted at 2021-02-11

フォルダ・ファイル容量測定Powershell

指定ディレクトリ内のフォルダ・ファイル容量(1MB以上)をすべて算出するPSスクリプト

Get-DirectoryVolRer.ps1
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 1}


    foreach($e in $children) {
        if ($e.Size -gt 1) { # 1MB以上をチェック対象とする
            Write-Output ($e.FullName + ',' +  $e.Size)
            if (Test-Path $e.FullName -PathType container) {
                Set-Location $e.FullName
                getFuckinHeavyWeightData($e.FullName)
            }
        }
    }
}

# 対象フォルダ指定
$root = "\\192.168.3.30\book"

# 出力ログパス指定
$outlogpath =  "D:\home\logs\Get-DirectoryVolRecRec_$times.log"

# 時刻取得
$times = Get-Date -Format "yyyyMMddhhmmss"

# ログ出力
getFuckinHeavyWeightData($root)  | Tee-Object -FilePath $outlogpath

# ホームディレクトリに戻って終了
Set-Location $HOME
Write-Host ("処理を完了しました。")
0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?