A friend of mine works for a software company, looking after a test rig for one of their product families.Â The test rig is based on Hyper-V, and they have to frequently provision lots of virtual machines to test new products.Â We were chatting about how they do this a few weeks ago and I thought â€śI bet I could do that using PowerShell, and I bet I could create a very nice solution tooâ€ť.Â What I wanted: A PowerShell script that would make lots of Windows Server 2012 (WS2012) Hyper-V VMs from a comma separated values (CSV) file.Â I also thought that this would be a great demonstration of PowerShell during WS2012 Hyper-V demos that Iâ€™m frequently doing.
So I put some work into it.Â The concept is based on a previous script that I wrote, but I took it to the Nth degree.
Hereâ€™s how my script works:
- You create a CSV file that specifies the configuration of each VM (1 row per VM).
- You edit the script to read that file (easy change near the top)
- You run the script
- The results are recorded in a log file that you specify in the script (a second easy change near the top)
Iâ€™ve put instructions in the script.Â Iâ€™ve also supplied a sample CSV file in the zip file to show three different types of VHDX creation.
The script allows you to specify the following in the CSV:
- Storage location of the VM
- Name of the VM
- Processor count
- Virtual memory, including Dynamic Memory if you want
- VHDX type and configuration, including Fixed, Dynamic, and Differencing
So how could you use the script?
- Maybe you want to create lots of pooled or personal VMs
- Possibly you need to deploy a demo lab with lots of VMs
- Maybe you are like my friend, working in a large software test environment, and youâ€™d like to deploy lots of VMs, and youâ€™d like to be able to vary the specification and build of those VMs
Thereâ€™s nothing to stop you from editing the script and either adding/removing functionality.Â If you find it useful, then go ahead and use it.Â In fact, if you do use it, then tell me how because Iâ€™ll be interested.
This script is not supported by me.Â Use and/or modify the script at your own risk.
Please note that this script is mine and you may not re-share it without my permission.Â Please link to this blog post instead.
You can download the script and sample CSV file from here.
- Add remote host functionality
- Add cluster functionality
- Start VMs
This information has been brought to you by Windows Server 2012 Hyper-V Installation and Configuration Guide (available on pre-order on Amazon) where youâ€™ll find lots of PowerShell like in this script:
This blog post is the property of Aidan Finn (@joe_elway / http://www.aidanfinn.com) and may not be reused in any manner without prior consent of Aidan Finn. You may quote one paragraph from this blog post if you link to the original blog post.
- Easily Convert Your VMware Virtual Machines to Hyper-V Using Virtual Machine Converter Solution Accelerator
- Backing Up Hyper-V Replica Virtual Machines In The DR Site
- Is Dynamic Memory Coming To Linux Virtual Machines on Hyper-V?
- Windows Server 2012 R2 Hyper-V – Generation 2 Virtual Machines
- Hyper-V PowerShell Script Cookbook on TechNet Wiki