We have a problem that a lot of VI administrators (especially us young ones) run into - VM Sprawl.

In attempting to reduce the chaos and get a much better understanding of our virtual infrastructure I’ve run into a very helpful cmdlet provided in the VI Toolkit.

This tutorial is intended for the complete novice.

Step 1:

Get your system set up for VI Toolkit.

Download PowerShell. Download the VI Toolkit. Step 2: Preparing your PowerShell environment.

Go to Start -> Run and type powershell. Press enter.

[sourcecode language=‘jscript’] echo $profile # C:\Documents and Settings\ME\My Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1 [/sourcecode]

See Windows PowerShell Profiles to set up a profile.

Run

[sourcecode language=‘jscript’] new-item -path $profile -itemtype file -force [/sourcecode]

If you’re familiar with bash, think of this as a /~/.bash_profile. Any “aliases” or cmdlets you place in here can be accessed throughout your powershell session.

A notepad window should open. If it didn’t, run the following command:

[sourcecode language=‘jscript’] notepad $profile [/sourcecode]

Now, paste the Get-VMStat cmdlet in your profile.

[sourcecode language=‘jscript’] function Get-VMStat { param( $VM,[Int32]$Hours = 1 ) $VM | Sort Name | Select Name, @{N=“CPU”;E={[Math]::Round((($_ | Get-Stat -Stat cpu.usage.average -Start (Get-Date).AddHours(-$Hours) -IntervalMins 5 -MaxSamples ($Hours*12) | Measure-Object Value -Average).Average),2)}}, @{N=“MEM”;E={[Math]::Round((($_ | Get-Stat -Stat mem.usage.average -Start (Get-Date).AddHours(-$Hours) -IntervalMins 5 -MaxSamples ($Hours*12) | Measure-Object Value -Average).Average),2)}} } [/sourcecode]

Save your profile.

Step 3: Use the cmdlet.

Launch the VI-Toolkit (Start > Programs > VMware > VMware VI Toolkit)

Then, run the following:

[sourcecode language=‘jscript’] Get-VC # you will be asked for your VC server Get-VMStat (Get-VM) -Hours 2160 [/sourcecode]

2160 hours gives the average CPU and RAM for all of my VMs for the last 90 days. This is giving us a wonder baseline of information to make some resource allocation decisions.