PowerCLI Quick One-liner: List VMs, Current Datastore, and Total HD size

28 September 2010

I wrote this quick one-liner when I was tasked to perform an audit of our VMs in a specified cluster to determine if they could be moved to a different LUN. The current setup, although functional, doesn’t truly utilize our Clarion’s two types of drives effectively (SATA, SCSI). This script is just the first step in our plan to reclaim the various LUNs and implement a more cost-effective layout.

Note that this may not be a true one-liner as it requires a few variables that I have stored in my profile:

Code

[vSphere PowerCLI] D:\> $HDPrimarySize = @{
>>     Name = "Primary HD Size (GB)"
>>     Expression = { $_.HardDisks[0].CapacityKB / 1MB }
>> }
>> $HDSecondarySize = @{
>>     Name = "Secondary HD Size(GB)"
>>     Expression = { $_.HardDisks[1].CapacityKB / 1MB }
>> }
>> $TotalHD = @{
>>     Name = "Total HD Capacity"
>>     Expression = { ($_.HardDisks[1].CapacityKB / 1MB) + ($_.HardDisks[0].CapacityKB / 1MB)}
>> }
>>

[vSphere PowerCLI] D:\> get-cluster MyCluster | get-vm | select Name, @{N=”Datastore”;E={Get-Datastore –VM $_}},$TotalHD | sort Datastore | Export-CSV vms.csv

Comments (0) Trackback Leave a comment
  1. No comments yet.
Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
  1. No trackbacks yet.