How to create a MDT Reference VM with PowerShell

I’m using Microsoft Deployment Toolkit for quite a while now, for creating Reference Images. I used to use ConfigMgr in the past for this process, but there are some issues like failing of the Task Sequence if an Update requires multiple Reboots for example.

Since I made the turn to MDT, I’m actually pretty happy. The Task Sequence runs smoothly and what before took about 5-8 hours, is now done in 2-3 hours.

The only thing I didn’t like was the manual re-creation of the Reference VM, each and every time. The Reference VM should always be recreated before you want to make a new Image, to ensure that nothing is left from the previous attempt.

For this reason, I created a PowerShell Script, which pretty much does the following:

  1. Copying the Boot-Image from the Deployment Share to the Hyper-V Host
  2. Creating a Hyper-V VM with various, configurable options
  3. Mounting the Boot-Image
  4. Starting the VM
  5. Connecting to the VM using Virtual Machine Connection
  6. Checking every 15 seconds if the VM is still running
  7. Removing the VM and the VHDX, when the VM stops running

Configure the MDT Finish Action

For the Script to work, you need to make sure that the Reference VM is shutting down at the End of the Task Sequence. You can configure that in the Rules Section in the Properties of the Deployment Share

ReferenceVM_Part1

ReferenceVM_Part2

Implementing the PowerShell Script

You can download the Script from GitHub.

After downloading, copy the Script to your Hyper-V Host and configure the option variables in the beginning of the Script according to your needs. The options should be self-explaining, however if you have any questions, drop them in the comment section below.

At last you can configure a shortcut, e.g. on the Public Desktop, which is pointing to the PowerShell Script. With the Name Attribute, you can specify the name of the Virtual Machine, which can be useful if you want to use multiple Reference VMs at the same time.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command "C:\Scripts\New-ReferenceVM.ps1 -Name REF001"

ReferenceVM_Part4

ReferenceVM_Part5

ReferenceVM_Part6

So that’s it. You now get a fully configured Virtual Machine with a simple DoubleClick.

Rate this post

5 Comments

  1. Patrick Seymour 18. February 2016
  2. censor 15. December 2017
  3. censor 15. December 2017
  4. censor 15. December 2017

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.