Skip to content

Instantly share code, notes, and snippets.

@h3nryza
Created July 17, 2018 17:32
Show Gist options
  • Select an option

  • Save h3nryza/457fed2208e605ee7807b899536bbd29 to your computer and use it in GitHub Desktop.

Select an option

Save h3nryza/457fed2208e605ee7807b899536bbd29 to your computer and use it in GitHub Desktop.
Powershell get disk space
$arrDisk = Get-WmiObject -class Win32_LogicalDisk
foreach($Item in $arrDisk)
{
$Name = $Item.DeviceID
$Caption = $item.VolumeName
$PercentFree = [math]::round( ( ($item.FreeSpace /$item.Size)*100),2)
$PercentUsed = [math]::round( (( $item.Size - $item.FreeSpace )/$item.Size)*100,2)
$FreeSpace = [math]::round($item.FreeSpace/1gb,2)
$UsedSpace = [math]::round(($item.Size/1gb - $item.FreeSpace/1gb ),2)
$TotalSize = [math]::round($item.Size/1gb,2)
write-host "Drive `t:$Name `nLabel `t:$Caption `n%Free `t:$PercentFree% `n%Used `t:$PercentUsed% `nFree `t:$FreeSpace GB `nUsed `t:$UsedSpace GB `nTotal `t:$TotalSize GB `n"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment