Hello everyone, I am taking a little different approach with this post. Instead of putting the script directly into the body of the post I decided to give GitHub a try. Link below.
As with anything, this script came from a business need. We had an application and that application needed to be available in a development environment for testing. The catch was that the development instance of the environment needed to be updated daily. In our case we are running a Windows domain, so in order for it to be an isolated copy, it had to include some infrastructure components, like a Domain Controller.
Thus this PowerCli script was born. Took me quite a while to come up with it. Basically in a nutshell it will clone production VMs, change the portgroup of each VM, then power on those clones in a particular sequence. The next time it runs, it will power off the old clones, delete them, then do it again. So all VMs are isolated onto a particular network (portgroup) and powered on using all the same IP settings. In my case I have a little virtual pfsense box that sits with one interface on our production LAN and one interface in the dev portgroup network doing NAT so that end users can RDP into one of the servers.
Because we only have the vSphere standard license, we don’t have the DRS feature. For those not familiar with this feature, Distributed Resource Scheduler. It’s a background task that automatically moves VMs to different hosts in the cluster based on load. For example it may even out memory usage across all hosts or if one host is high in CPU utilization identify a VM that can be moved so that CPU load is spread more evenly. So in our case with only standard licensing and no DRS, it was a concern that automatically powering on VMs might bring them up on a host that was already at capacity. To deal with this, I included a PowerCli function that would measure memory utilization on each host and move the VM to the host with the most available RAM prior to power on. I realize this doesn’t consider CPU load, but in my case we have CPU to spare and it wasn’t a concern. Memory on the other hand always seem to be in short supply.
So I hope this helps someone out there. When management first came to us with this requirement of a nightly dev environment, we weren’t sure quite how we were going to pull it off. Seems like a very custom solution. Here is the link to the GitHub repo with the code. Thanks for stopping by!Click Here: PowerCLI-Automate-Dev-VM-Copies