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.

The script I am using is posted on GitHub. I also posted a very low budget video on YouTube that demos the process. This will give you a good understanding.


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.

Required Input

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:
      • Device-
      • Computer-
    • 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:
      • 10
    • End Number (Suffix of machine)
      • End of range, for example:
      • 30
    • Desired VMs (How many VMs do you want to create on this run?)
      • Total machines created, for example:
      • 5
    • 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

Test Run

HyperV Automate 01

I’ve set it to create 5 machines. They start with Recast and will be between 01 and 90, depending on what is available.

HyperV Automate 02

You can see here, I already have some machines with those names. Now let’s run the script and see what happens.

HyperV Automate 03
HyperV Automate 04

So, that looks good…
HyperV Automate 05
HyperV Automate 06
HyperV Automate 07

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
Request Pricing

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:

Share this: