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:
- Copying the Boot-Image from the Deployment Share to the Hyper-V Host
- Creating a Hyper-V VM with various, configurable options
- Mounting the Boot-Image
- Starting the VM
- Connecting to the VM using Virtual Machine Connection
- Checking every 15 seconds if the VM is still running
- 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
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"
So that’s it. You now get a fully configured Virtual Machine with a simple DoubleClick.