Colin Westwater

MDT Gold Image VM Automation

As part of my role I maintain and develop our Microsoft Deployment Toolkit (MDT) infrastructure. It’s a fantastic tool for automating the deployment of your corporate images.

One vital task is to maintain the Gold images with the latest Windows updates. I tend to do this monthly to speed up deployments. As part of this task I was manually creating a new VM, customising it then launching the deployment. Non value add work!

So I turned to PowerCLI to automate the creation of the VM’s for our Windows 7 and 10 Gold images. My goal was to also make this as simple as possible so I could hand off to our Service Desk Tier II team.

As part of that I wanted to make the script have a simple menu where the person running the script could select either Windows 7 or Windows 10. This is actually quite simple using the System.Management.Automation.Host.ChoiceDescription class in PowerShell. There is a good TechNet article here on the procedure.

So the flow of the script is as follows.

First we need to declare our variables: the vCenter, the path to the WinPE ISO file for booting the VM into MDT, the datastore we put the VM onto, the Network and the actual host we want the VM on.

Next we connect to vCenter, pretty straightforward. I like giving some feedback on the console so it says if it connects or not.

Next we create the menu. We create some variables for the menu such as the title, a description and then the three options we want to present. These are Windows 7 GOLD Image, Windows 10 GOLD Image, and Exit. The last line of the menu portion builds the menu on screen. Depending on the option chose the menu returns a value of 0, 1 or 2. The script then jumps to the portion that matches this value using and If statement.

The building of the VM for Windows 7 or 10 is pretty similar. All that is different is the VM name and the GuestID. First of all we check to see if there is already a VM of the same name in vCenter, Maybe we forgot to delete it after we captured the image. I don’t bother confirming the deletion of the VM. Next we create the VM with a CD drive, on the datastore specified in the variable, 32GB HDD, Thin provisioned, the correct GuestID, 6GB RAM, 2 CPU’s, on the Production network and on the correct host.

If you want to specify a VMXNET3 nic you can comment out the next line. Next we have to remove the existing CD drive, then add one back in pointing to the WinPE ISO file.

Finally we power on the VM. It boots to the WinPE ISO file which then connects the VM to the MDT Deployment share. I like cleaning up after myself so we disconnect from vCenter.

The script is pretty simple, but I estimate is saves me 10-15 minutes each time I want to create an image. Multiply that over the number of images created in a year and it’s a pretty good time saving.