0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShellで各ディレクトリサイズの合計を表示したい

0
Posted at

指定ディレクトリ直下の各ディレクトリサイズの合計を表示する

Windowsで各ディレクトリの合計値を確認したい時
エクスプローラーで確認するのも毎回面倒だし親ディレクトリしか合計サイズ分からない

Get-DirectorySizes.ps1
# 例としてC直下を指定
$path = "C:\"
$totalSize = 0

Get-ChildItem -Path $path -Directory | ForEach-Object {
    $size = (Get-ChildItem $_.FullName -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object -Property Length -Sum).Sum / 1GB
    Write-Host ("{0}: {1:N2} GB" -f $_.Name, $size)
    $totalSize += $size
}
Write-Host "--------------------"
Write-Host ("合計: {0:N2} GB" -f $totalSize)

各ディレクトリと全体のディレクトリサイズを表示する。

出力例
PS C:\Work\PowerShell> .\Get-DirectorySizes.ps1
# ...
# Install Module: 2.45 GB
# PerfLogs: 0.00 GB
# Program Files: 25.02 GB
# Program Files (x86): 5.22 GB
# Work: 59.92 GB
# SWSetup: 0.42 GB
# TEMP: 4.64 GB
# Users: 7.51 GB
# Windows: 45.74 GB
# ...
# --------------------
# 合計: 154.19 GB
PS C:\Work\PowerShell>
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?