Recently I had a project for which I needed about 300 virtual machines. I already had a bare metal with Quad Processors and 512GB Ram loaded with Windows 2012 R2 and Hyper-V. I was sure it would handle at least 100 VMs easily with 4GB ram each. Now the difficult task to create these big number of virtual machines which was way too time consuming and boring task.
So my next step was to Google and find out how I could create bulk VMs on Hyper-V. As per my knowledge, Hyper-V doesn’t have any option to create VMs in bulk quantity. So I had to go with PowerShell. PowerShell was already installed on my bare metal. I will try to explain what I did in steps below.
Cmdlets is a library of few commands specific for Hyper-V and helps creating and managing virtual machines through PowerShell. You can download CMDlets from Codeplex website. You can learn about its commands Microsoft technet website.
Microsoft technet blog has a very good ready to use script for creating bulk virtual machines. This helped me the most. Download it here. However it does not give you the CSV file which you have to use to create bulk virtual machines. For your help, I will attach the CSV file same below. You also have to prepare a virtual machine manually via Hyper-V first which will be used as a template.
So I logged into Hyper-V and created the first virtual machine and named it as “Template Win 2008 R2”. Then I logged into the virtual machine, brought it on public internet using the additional IP address and using Google DNS server. Once the desktop is loaded, I installed the necessary software on it. Like Google Chrome browser, Winrar or whatever I needed to use.
Now your template VM is fully ready and shut down mode, the PowerShell script will be able to copy its hard disk (example.vhdx) for new VMs.
Now we have to prepare our CSV file with a list of VMs we want to create. You can download the sample CSV file here. I will explain a little bit about each column in the CSV file.
Next step is to open PowerShell in your Windows 2012 R2. Type or copy the following command.
Change the path to the script and make sure it is unlocked to execute in PowerShell.
Once you run the script, you should be able to see the PowerShell creating the VMs for you and will be showing you output with results like below.
I hope the above tutorial helps and works smooth. Please feel free to leave the comment below with your feedback or questions.
Sources: Image credits and tutorial is referenced from Microsoft Script Center.