VM Junkie

August 20, 2009

Powershell one-liner

Filed under: powershell, vmware — ermac318 @ 10:20 am

One of my favorite blogs as of late has been Arne Fokkema’s ICT-Freak, mostly because he enjoys posting little Powershell snippets that he writes. I find these one-liners are often very educational and often very useful, so I thought I’d start doing the same.

Recently at a customer site we migrated 100+ VMs from old storage to new storage, then upgraded them to vSphere. The customer left a few VMs on the old system however, and they asked for a way to identify them at a glance and how big they were. I cooked up this one-liner to list a bunch of VMs, their datastore, and their size in GB:

Get-VM | Select Name, @{N="Datastore";E={(Get-Datastore -VM $_).Name}}, @{N="VMSizeInGB";E={(get-harddisk -vm $_ | Measure-Object -Property capacityKB -sum).Sum / 1024 / 1024}}

1 Comment

  1. Rather the divide by 1024 twice, would it not be faster to divide by 1048576 once? Granted, we all know what 1024 represents here, and 1048576 might not be as clear to someone reading the code.

    Comment by d_glynn — August 20, 2009 @ 12:24 pm

RSS feed for comments on this post.

Sorry, the comment form is closed at this time.

Create a free website or blog at WordPress.com.

%d bloggers like this: