Scripting a DRS Replacement Using PowerCLI

One of the things that I LOVED about having an evaluation copy of vCenter (other than Storage vMotion) is the use of Distributed Resource Scheduler (DRS). I loved the fact that I could let my VMs live on their own and vCenter would intelligently balance the load across all the VM hosts (and shut them down if they weren’t needed). When I finally had to move from the eval mode to a licensed server I felt a little let down because some of my VM hosts would be at 30% memory utilization while others would be at 70% memory utilization. Maybe it’s just me but that seems like a real waste of resources. 🙂

I recently found out it’s really bad when you need to power off a host for maintenance and then need to move the VMs back to the original host. To make my life a lot easier I created the following script. It balances memory usage across all the hosts to about 10% of the average. I also make certain specific VMs always placed on certain hosts (my vCenter server is always on the first host and my SQL servers are always on different hosts). This feature is enabled if a CSV is located in the same directory as the script (named balanced.csv) with a Name column and a host column that have the name of the VM and the host it should be placed on respectively. The script assumes you already have a connection to your vCenter server (using Connect-VIServer).
Continue reading