Helpful script of the day: HA calculations
I’m seeing a lot of posts on different forums about VMware HA.
Some people, including myself, have been receiving error messages when trying to power on a vm in a HA cluster like this one:
“Insufficient resources to satisfy HA failover level on cluster x in y”
Some fellow bloggers have preceeded me in providing clear explanations on how HA actually calculates this sort of thing. For instance:
http://virtualgeek.typepad.com/virtual_geek/2008/06/so-how-exactly.html
Now, I still see a lot of replies from people that are having difficulties calculating exactly what happens in their situation. For those people, I have created a Powershell / VI Toolkit (beta) script that does the math and shows you exactly what is going on in your cluster.
So, download it, try it, and please send me some feedback if you have questions, remarks or problems.
Hope this helps.
No related posts.
14 Responses to Helpful script of the day: HA calculations
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





I get errors running this script – am I doing something wrong… I am saving file as .ps1 then calling it from Powershell but I get the following:
The term ‘Get-VIServer’ is not recognized as a cmdlet, function, operable program, or script file. Verify the term and
try again.
At C:\ha.ps1:29 char:19
+ $VC = Get-VIServer <<<< $VCServerName -ErrorAction Stop
Get-Cluster : 02/09/2008 5:05:19 p.m. Get-Cluster You are not currently connected to any servers. Please conn
ect first using Connect-VIServer or one of its aliases.
At C:\ha.ps1:31 char:23
+ $Cluster = Get-Cluster <<<< $ClusterName
Get-View : The argument cannot be null or empty.
At C:\ha.ps1:32 char:23
+ $ClusterAdv = Get-View <<<< $Cluster.Id
Get-VM : 02/09/2008 5:05:19 p.m. Get-VM You are not currently connected to any servers. Please connect first
using Connect-VIServer or one of its aliases.
At C:\ha.ps1:43 char:14
+ $VMs = Get-VM <<<< -Location $Cluster | Sort-Object Name
Attempted to divide by zero.
At C:\ha.ps1:49 char:86
+ Write-Progress -Activity “Processing VMs” -Status $VM.Name -PercentComplete (100*$i/$ <<<< j)
Get-View : The argument cannot be null or empty.
At C:\ha.ps1:52 char:19
+ $VMadv = Get-View <<<< $VM.Id
Get-VMHost : 02/09/2008 5:05:19 p.m. Get-VMHost You are not currently connected to any servers. Please connec
t first using Connect-VIServer or one of its aliases.
At C:\ha.ps1:69 char:22
+ $VMHosts = Get-VMHost <<<< -Location $Cluster | Sort-Object Name
Attempted to divide by zero.
At C:\ha.ps1:75 char:94
+ Write-Progress -Activity “Processing VMHosts” -Status $VMHost.Name -PercentComplete (100*$k/$ <<<< l)
Get-View : The argument cannot be null or empty.
At C:\ha.ps1:78 char:23
+ $VMHostAdv = Get-View <<<< $VMHost.Id
Hi Mark,
That script was created for use with the BETA of the VI Toolkit. All you need to do is replace Get-VIServer with Connect-VIServer and it should work fine.
Consider ending the script with a Disconnect-VIServer (see http://www.peetersonline.nl/index.php/vmware/to-disconnect-viserver-or-not-to-disconnect/#more-50)
I’m not a scripting guy I would absolutely LOVE to see the algorithm for this. The page I linked from had typos all over it.
Nice script. I found an error in that was causing it not to calculate the MemSlots properly though.
This line:
Else {$MemRes = [math]::Round(($VMadv.resourceconfig.memoryallocation.reservation / 1MB),0)}
Doesn’t need to be divided by 1MB as the number is already in megabytes. I changed to this:
Else {$MemRes = [math]::Round(($VMadv.resourceconfig.memoryallocation.reservation),0)}
Thanks for your input Jason!
Just ran this script Hi Hugo i am runing your script Get-HAClusterSize and am a bit confused.
The results am getting are
Your heaviest VM in terms of CPU usage is considered to be:
a CPUSlot of 512 and a MemSlot of 522..but the server in question has 4GB of RAM…
Am not sure how you are getting these figures….
VMware uses a minimum amount of RAM needed for the VM to run for the calculation, which makes sense in the light of overcommitting your physical servers. In simple words, they say: If you lose your heaviest ESX server, let’s reserve at least enough space to host (total number of vm’s) times (*minimum* amount of resources your *heaviest* vm requires). Then we will probably be safe, because the rest of your vm’s is lighter. If they would use the allocated amounts of RAM, you will not be able to put as many vm’s on your cluster while satisfying a certain HA Failover Level.
[...] epping wrote an blog about it. These blogs where the first blogs out there regarding this subject. Hugo peeters also made a great script for calculation the [...]
hi
great script worked like a charm.. but i am having trouble understanding the results. The line at the bottom “you should have room for another -2vms while maintaining a failover of level of 1″ does this mean minus 2 or is that just the way the script displays the text.
or does this mean that two of the VMs on the heaviest host will not boot?
Hi Jason,
That reads as minus two. Please note that the HA algorithm has been changed by VMware (I think since ESX3.5U4). It no longer multiplies by the highest number of vcpus in any of your vm’s. This makes the output of my script invalid.
In the vSphere client, on the Summary Tab of your Cluster, click the Advanced Runtime Info link in the VMware HA section to show the HA adminssion control / failover level calculations.
Hugo
The current version of ESX on the cluster is currently 3.5.0 153875 does this mean the script is still valid? I do not have a advanced Runtime Info link in the HA Section just
Do not Allow constraint Violations
Configured failover 1
Current failover Capacity 3
Thanks for the help
Hi Peter, your script is great!
I grabbed it and modified it to stick to my needs.
Now it runs inside vCheck v5 and give me HA Slot Size reports for ESX3.5/vCenter2.5 environments
I’ll blog about it shortly…
Cheers,
Didier
[...] there isn’t any! Almost any actually… I found out a great blog post by Hugo Peeters @ http://www.peetersonline.nl who gives out a Powershell script that does exactly [...]
Hi, I am unable to run the script, I get the follwong message
Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern ‘VMware.VimAutomation.Core’ were found. Check the pa
ttern and then try the command again.
At line:1 char:18
+ If ((Get-PSSnapin <<<< VMware.VimAutomation.Core) -eq $null)
+ CategoryInfo : InvalidArgument: (VMware.VimAutomation.Core:String) [Get-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.GetPSSnapinCommand
Connect-VIServer : 9/16/2011 8:35:39 AM Connect-VIServer Could not resolve the requested VC server.
At line:5 char:23
+ $VC = Connect-VIServer <<<< $VCServerName -ErrorAction Stop
+ CategoryInfo : ObjectNotFound: (:) [Connect-VIServer], ViServerConnectionException
+ FullyQualifiedErrorId : Client20_ConnectivityServiceImpl_Reconnect_NameResolutionFailure,VMware.VimAutomation.Vi
Core.Cmdlets.Commands.ConnectVIServer
I run the command Add-PSSnapin VMWare.VimAutomation.Core and then get the following error:
Get-PSSnapin : No Windows PowerShell snap-ins matching the pattern 'VMware.VimAutomation.Core' were found. Check the pa
ttern and then try the command again.
At line:1 char:18
+ If ((Get-PSSnapin <<<< VMware.VimAutomation.Core) -eq $null)
+ CategoryInfo : InvalidArgument: (VMware.VimAutomation.Core:String) [Get-PSSnapin], PSArgumentException
+ FullyQualifiedErrorId : NoPSSnapInsFound,Microsoft.PowerShell.Commands.GetPSSnapinCommand
What am I missing??