Oneliner for the road

Okay, so I’ve just announced I won’t  post anything for the coming month. You must all feel very sad.

Well, before leaving you sobbing over an empty feed reader, here’s one more oneliner. One for the road.

Get-VMHost | Sort Name | Get-View | Select Name, @{N=”MemoryGB”;E={[math]::Round((($_.Summary.Hardware.MemorySize)/1GB),0)}}, @{N=”MemoryUsageGB”;E={[math]::Round((($_.summary.quickstats.overallmemoryusage)*1MB/1GB),2)}}, @{N=”Percentage”;E={[Math]::Round(100*(($_.Summary.QuickStats.OverallMemoryUsage*1MB/1GB)/($_.Summary.Hardware.MemorySize/1GB)),0)}}

What the *bleep* does that do? I’ll explain it to you:

  • It grabs your VMware Servers (Get-VMHost)
  • Sorts them by Name (Sort Name)
  • Gets the advanced properties (Get-View)
  • Selects some properties to show you (Select), being:
    • The server Name (Name)
    • Something called MemoryMB, which is the value of the Summary.Hardware.MemorySize property devided by 1 GB and rounded to zero digits.
    • Something called MemoryUsageGB, which is the value of the Summary.QuickStats.OverallMemoryUsage property (which is already in MBs), converted to GBs and rounded to two digits.
    • Something called Percentage, which is 100 times the MemoryUsage in GBs divided by the Memory in GBs, rounded to zero digits.

Can’t you do something like that with Get-Stat?
Sure, but wouldn’t be near as much fun.


2 thoughts on “Oneliner for the road

Leave a Reply