Leveraging Hyper-V to Automate OSD Test Machines
While Hyper-V isn’t directly related to ConfigMgr, many of you might be using it for hosting labs or test machines. I’m not going to go over why I am a huge fan of Hyper-V, but I do like the price, and the integration with PowerShell.
On this page, I’m going to cover the process I’m using to create multiple VMs for testing.
Automate the build of VMs. These will then be used to test operating system deployment (OSD) task sequences.
I do a lot of task sequence testing and I was tired of all the extra clicks to create VMs in order to perform these tests. I knew that everything I wanted to do was possible with PowerShell, so I sat down for a few hours one night and did it.
In a nutshell, the script will create VMs in Hyper-V and create the associated device object in ConfigMgr.
It’s a bit more involved than that, so let’s go over the requirements.
- The script was designed to be run on the Hyper-V host.
- Required Info:
- Site Code
- ConfigMgr Provider
- Location to the CM PowerShell Module (to import)
- Path to Where to Store the VM
- Prefix (the name you want to call the device) for example:
- Boot ISO Location (If you want to boot to ISO)
- Hyper-V Virtual Adapter Name
- ConfigMgr collection where you want the machine added.
- Start Number (Suffix of machine)
- Start of a range of numbers to append to the machine to keep unique, for example:
- End Number (Suffix of machine)
- End of range, for example:
- Desired VMs (How many VMs do you want to create on this run?)
- Total machines created, for example:
- Time Between Kickoff
- This is the amount of time between starting up each VM, as to not overload your Hyper-V host with starting and imaging all the machines at the same time.
Once you’ve updated the script with those options, you just push “Go” and it will do what you want.
Let’s talk through a scenario
I’ve set it to create 5 machines. They start with Recast and will be between 01 and 90, depending on what is available.
You can see here, I already have some machines with those names. Now let’s run the script and see what happens.
From the images, you can see it did what I wanted. It created the VMs and devices in ConfigMgr, accounting for ones already created as to avoid duplicates.
Now it’s easy to quickly create new test machines for application deployment tests, OSD task sequence change tests, or just adding several machines to test patching on. Hyper-V + ConfigMgr + PowerShell = Awesome.
About Recast Software
1 in 3 organizations using Microsoft Configuration Manager rely on Right Click Tools to surface vulnerabilities and remediate quicker than ever before.
Download Free Tools
See how Right Click Tools are changing the way systems are managed.
Immediately boost productivity with our limited, free to use, Community Edition.
Get started with Right Click Tools today: