VI Toolkit One Liner: Who’s busy ?

Most of my work with the VI Toolkit has been scripts so far, well the work that I  have added to this blog anyway, I use one-liner’s on a daily basis to make my job easier.

It was suggested to me that I should add some one-liners to my blog as I’m going to be busy over the next couple of weeks so I had a quick tinker.

This one-liner is quite a simple but long one-liner just to get started:

View the top 10 VM’s which have been using memory for the last 48 Hours:

Get-Stat -Entity (Get-VM | Where {$_.PowerState -eq "PoweredOn"}) -Start ((Get-Date).AddHours(-48)) -Finish (Get-Date) -Stat mem.usage.average | Sort-Object Value -Descending | Select-Object Entity, Value -First 10

Or because it doesn’t fit the length of the blog I will break it down a little:

Get-Stat -Entity (Get-VM | Where {$_.PowerState -eq "PoweredOn"}) 

  -Start ((Get-Date).AddHours(-48)) -Finish (Get-Date) -Stat mem.usage.average 

  | Sort-Object ValueDescending 

  | Select-Object Entity, Value -First 10

Obviously this can be changed to use the last week (-168) or last 24 (-24) hours, it can also be changed to get the busiest hosts by changing Get-VM to Get-VMHost.

The stat can also be changed to get the busiest CPU or Disk or most other stats:

% CPU Usage – cpu.usage.average 

Mhz CPU Usage – cpu.usageMHZ.average 

% Memory Usage – mem.usage.average 

Kbps Network Usage – net.usage.average 

Kbps Disk Usage – disk.usage.average 

The trick with these one liners is to break them down and follow them through slowly, working out what is being passed along the pipeline.

As I have heard people say before, its not the length its what you can do with it, this one has both length and usage !

Now to come up with some more useful one-liners…

3 thoughts on “VI Toolkit One Liner: Who’s busy ?

  1. Albert Widjaja

    Thanks you Sir,

    This is a very useful script to learn.

    Thanks for sharing.

  2. Virtu-Al


    This is because by default the Get-Stat gets multiple samples from the objects, you can add -MaxSamples 1 to the pipeline just after get-stat to make sure it only retrieves 1 sample per VM.


  3. seaJhawk

    Cool tip Al.

    Question, when I run the script as-is, out of the top 10 VMs that are shown, there are only 4 unique VMs. Each instance of the same VM has a different value.

    Any ideas why I’m seeing duplicates?


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.