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.
I do a similar thing, except I don’t delete the VM each time. I created a fresh VM for each task sequence, and immediately created a snapshot (Checkpoint in Hyper-V jargon). I just roll back to this snapshot when I need a clean VM. Having VMs with known UUIDs lets me map UUIDs to task sequences in MDT’s CS.ini, so I don’t even have to pick a task sequence during the build process.
That is also a possibility, thanks for sharing 🙂
Do u mean that the vm have to be created with a dvd device before run the script, becaurse the script wont do it?
I have tried to mkae a dvd drive with
Get-VM $vmname | Add-VMDvdDrive -ControllerNumber 0 | Set-VMDvdDrive -VMName $vmName -Path $bootIso -Verbose
This is a Gen 2 vm and the iso should mount on scsi drive but it wont?
i solve it with
#Create new DVD Drive
Get-VM $vmName | Add-VMDvdDrive -ControllerNumber 0
#Set First Boot Device
$dvd = Get-VMDvdDrive -VMName $vmName
Set-VMFirmware -VMName $vmName -FirstBootDevice $dvd
But now it have to boot on dvd with no keystroke needed ?