Poor man’s DRS – Rebalance a vSphere Standard Cluster

Posted: February 13, 2013 in Scripts, VMware

DRS is a great feature, but more and more, I’m finding clients who just need a very simple cluster setup, but only want to pay for vSphere Standard licenses. Well, the script below can be used to run a job that will randomize the list of VMs in a cluster and then balance them across all hosts in the cluster. This is purely a VMs/host type of balance, not a resource balance like DRS. But, I set this up to run once a week on a few client’s DEV clusters and it generally keeps things pretty even. Also very useful for post maintenance re-shuffles.
This is set to be run from the vCenter itself. Be sure to change $ClusterName to suit and if you want to run from another machine, change the VIServer lines as well.

$ClusterName = "ClusterName"

Connect-VIServer localhost

[array]$Hosts = Get-VMHost -Location $ClusterName
$HostCount = $Hosts.Count

$VMs = Get-VM -Location $ClusterName
$VMs = $VMs | Get-Random -Count $VMs.Count

$Count = 0

ForEach ($VM in $VMs){

$HostNumber = $Count % $HostCount
Move-VM $VM -Destination $Hosts[$HostNumber] -RunAsync

Disconnect-VIServer localhost -Force -Confirm:$false


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s