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…