Monthly Archives: March 2012

PowerCLI and Storage

Below are some interesting sets of PowerCLI commands that will give you more information on your VM’s hard drives and your datastores.

The below will give you the total allocated hard drive space of all the VM’s in a cluster.

Get-Cluster "Cluster Name" | get-vm | Get-HardDisk | %{ $vmCapacity += $_.capacityKB }
$vmCapacity

The below will give you the Total Capacity, Free Space, and Usage of your datastores.

Get-Datastore | %{ $datastoreFreeSpace += $_.FreeSpaceMB }
Get-Datastore | %{ $datastoreTotalCapacity += $_.CapacityMB }
$datastoreUsageTotal = $datastoreTotalCapacity - $datastoreFreeSpace

write-host "Total Capacity: $datastoreTotalCapacity MBs"
write-host "Total Free Space: $datastoreFreeSpace MBs"
write-host "Total Usage: $datastoreUsageTotal MBs"