Skip to content

Instantly share code, notes, and snippets.

@KentaGoto
Created August 13, 2023 06:54
Show Gist options
  • Save KentaGoto/d861b05798963a6659f6d296a671bbda to your computer and use it in GitHub Desktop.
Save KentaGoto/d861b05798963a6659f6d296a671bbda to your computer and use it in GitHub Desktop.
# ドライブの使用状況を取得する
$diskUsage = Get-WmiObject Win32_LogicalDisk | Where-Object { $_.DriveType -eq 3 } | ForEach-Object {
[PSCustomObject]@{
'Drive' = $_.DeviceID
'UsedSpaceGB' = [math]::Round((($_.Size - $_.FreeSpace) / 1GB), 2)
'FreeSpaceGB' = [math]::Round(($_.FreeSpace / 1GB), 2)
'TotalSpaceGB' = [math]::Round(($_.Size / 1GB), 2)
}
}
# Out-GridView で結果を表示する
$diskUsage | Out-GridView -Title "Disk Usage"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment