Skip to content

Instantly share code, notes, and snippets.

@talatham
Created June 13, 2013 09:36
Show Gist options
  • Save talatham/5772463 to your computer and use it in GitHub Desktop.
Save talatham/5772463 to your computer and use it in GitHub Desktop.
Display the disk usage for a specified machine.
# Initialise machine name
$server = "<>"
# Get fixed drive info
$disks = Get-WmiObject -ComputerName $server -Class Win32_LogicalDisk -Filter "DriveType = 3";
foreach($disk in $disks)
{
$deviceID = $disk.DeviceID;
[float]$size = $disk.Size;
[float]$freespace = $disk.FreeSpace;
$percentFree = [Math]::Round(($freespace / $size) * 100, 2);
$sizeGB = [Math]::Round($size / 1073741824, 2);
$freeSpaceGB = [Math]::Round($freespace / 1073741824, 2);
Write-Host "$server,$deviceID,$sizeGB,$freeSpaceGB,$percentFree";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment