The good news is moving to an automated image creation is a far simpler task than one might assume, inverting the time you spend taking care of your image and the amount of time you spend driving innovation. Over the years, Mikael Nystrom put together a PowerShell-based solution called Reference Image Factory, which allows you to realize that future of fully automated image creation today. All you need is a Hyper-V enabled system and Microsoft Deployment Toolkit.
Imagine for a moment: you fire up a PowerShell script and a few hours later you get your shiny images. That's it. Simply put: the future of image creation is now. It is not a question of if but when and when is now. Pretty cool, right?
Unfortunately, there’s no one-size-fits-all solution as you need to consider the target platform and in some cases, Hyper-V is not the right hypervisor for the job. For example, a couple of months ago, I worked with a customer on implementing a Horizon Cloud DaaS with hosted infrastructure. When creating purpose-built OS images for VMware cloud platform you should use a VMware hypervisor (either VMware Workstation or ESXi will do) which makes it easy to deliver optimized, feature-rich, ready for deployment images.
If you are in the same boat as I am - first of all, I am sorry. Secondly, I did not want to deploy an ESXi host just for the sake of creating virtual machines templates for the hosted Horizon Cloud environment. Instead, I turned my attention towards VMware Workstation which is capable of exporting virtual machines in Open Virtual Format (OVF) format. You can then deploy the OVF template in the same or in a different environment.
So, I went ahead and modified Mikael's Reference Image Factory solution (remember, I am not a fan of reinventing the wheel) to work with Karsten Bott's excellent vmxtoolkit which allows you to control VMWare Workstation and virtually eliminates the technical requirements for manually creating Windows images for VMware environments. The resulting solution is available from my GitHub repository.
- Download following PowerShell modules: PSINI (converts CustomSettings.ini file to a hashtable and back), vmxtoolkit (a Powershell extension for VMware Workstation), PSFTP (a PowerShell module which allows you to connect and manage the contents of an ftp account). Extract the modules into the pre-created folders.
- Install VMware Workstation as your virtualization host.
- Install and configure Microsoft Deployment Toolkit (MDT) build.
- Create your build & capture task sequences.
- Modify the accompanying XML file to match your environment.
- Run the script.
Once you execute the script, it will run through the following steps:
The script will import external PS modules and parse the accompanying ImageFactory XML file containing configuration settings:
IMF32, Imagefactory 3.2 (VMware), 02/06/2018 09:03:54 IMF32, Logfile is C:\Setup\ImageFactoryForVMware\log.txt, 02/06/2018 09:03:54 IMF32, XMLfile is C:\Users\tolwyn\ImageFactory\ImageFactory.xml, 02/06/2018 09:03:54 IMF32, Importing modules, 02/06/2018 09:03:54 trying to get os type ... ==>Product Name: Windows ==>running vmxtoolkit for win_x86_64 ==>vmrun is C:\Program Files (x86)\VMware\VMware Workstation\vmrun.exe ==>vmwarepath is C:\Program Files (x86)\VMware\VMware Workstation ==>virtual machine directory from module load is C:\Users\tolwyn\Documents\Virtual Machines\ ==>default vmxdir is C:\Users\tolwyn\Documents\Virtual Machines\ ==>running VMware Version Mode 22.214.171.12470693 ==>OVFtool is C:\Program Files (x86)\VMware\VMware Workstation\OVFTool\ovftool.exe ==>Packertool is C:\Program Files (x86)\VMware\VMware Workstation\7za.exe ==>vdisk manager is C:\Program Files (x86)\VMware\VMware Workstation\vmware-vdiskmanager.exe ==>webrequest tool is .Net ==>isotool is C:\Program Files (x86)\VMware\VMware Workstation/mkisofs.exe IMF32, Reading from C:\Users\tolwyn\ImageFactory\ImageFactory.xml, 02/06/2018 09:03:54
The script will then connect to your deployment share, determine and upload x86 and x64 boot images to the ISOLocation folder and will also enumerate all active TS in the RefTaskSequenceFolderName folder.
IMF32, Verify Connection to DeploymentRoot, 02/06/2018 09:03:54 IMF32, Verify Connection to OVF share, 02/06/2018 09:03:54 IMF32, Connect to MDT, 02/06/2018 09:03:54 IMF32, Get MDT Settings, 02/06/2018 09:03:54 IMF32, Check if we should update the boot image, 02/06/2018 09:03:54 IMF32, Check if we should use MDTmonitoring, 02/06/2018 09:03:54 IMF32, Verify access to x86 boot image, 02/06/2018 09:03:54 IMF32, Access to \\mdt01\VMwareCapture$\boot\vmware_lti_x86.iso is ok, 02/06/2018 09:03:54 IMF32, Verify access to x64 boot image, 02/06/2018 09:03:54 IMF32, Access to \\mdt01\VMwareCapture$\boot\vmware_lti_x64.iso is ok, 02/06/2018 09:03:54 IMF32, Get TaskSequences, 02/06/2018 09:03:54 IMF32, Found 4 TaskSequences to work on, 02/06/2018 09:03:54 IMF32, Get detailed info about the task sequences, 02/06/2018 09:03:54 IMF32, 10_1703_SYSPREP Windows 10 Enterprise 1703 1.0, 02/06/2018 09:03:54 IMF32, 10_1709_SYSPREP Windows 10 Enterprise 1709 1.0, 02/06/2018 09:03:54 IMF32, 7_X64_SYSPREP Windows 7 Professional x64 1.0, 02/06/2018 09:03:54 IMF32, 7_X86_SYSPREP Windows 7 Professional x86 1.0, 02/06/2018 09:03:54
Then, it will create a VM for each of the task sequences, apply HW configuration based on the settings you provided in the ImageFactory.xml file, inject a randomly generated MAC address and update CustomSettings.ini with that information. The MAC address is used to preselect a task sequence and run a fully unattended installation.
IMF32, Upload boot image to VMware host, 02/06/2018 09:03:54 IMF32, Create the VMs on Host, 02/06/2018 09:05:11 Working on 10_1703_SYSPREP ==>Creating new VM 10_1703_SYSPREP[success] ==>setting GuestOS windows8srv-64 for 10_1703_SYSPREP[success] 10_1703_SYSPREP is created 10_1703_SYSPREP HW version set to 11 Windows 10 x64 detected. Replacing guest OS type... ==>setting GuestOS windows9-64 for 10_1703_SYSPREP[success] 10_1703_SYSPREP RAM set to 2048 MB ==>creating new 60GB SCSI Disk 10_1703_SYSPREP at C:\Virtual Machines\vmxtoolkit\10_1703_SYSPREP[success] C:\Virtual Machines\vmxtoolkit\10_1703_SYSPREP\10_1703_SYSPREP.vmdk is created for 10_1703_SYSPREP ==>adding Disk 10_1703_SYSPREP.vmdk at Controller 0 LUN 0 to 10_1703_SYSPREP[success] C:\Virtual Machines\vmxtoolkit\10_1703_SYSPREP is attached to 10_1703_SYSPREP 10_1703_SYSPREP has 2 vCPU WARNUNG: Adapter not present, will be added ==>configuring Ethernet0 as vmxnet3 with NAT for 10_1703_SYSPREP[success] 10_1703_SYSPREP is connected to vmxnet3 NAT interface vmxnet3 NAT interface on 10_1703_SYSPREP configured to use static MAC address 02:4B:9A:1A:A0:6B 10_1703_SYSPREP configured to use 2 monitors x64 OS detected. ==> Configuring IDE sata0:1 on 10_1703_SYSPREP[success] C:\Virtual Machines\ISO\vmware_lti_x64.iso is attached to 10_1703_SYSPREP 10_1703_SYSPREP display name set to 10_1703_SYSPREP Added REFIMAGE annotation to 10_1703_SYSPREP IMF32, Update the CustomSettings.ini file, 02/06/2018 09:05:14
The script will then power up the VMs and wait until all OSDs are finished (depending on the number of task sequences and ConcurrentRunningVMs setting this may take a while). Next, the script will export the VMs into the OVF format suitable for import into vSphere. The script will remove any entries from CustomSettings.ini added during the initialization phase and, depending on your EnableCleanup setting, will also destroy all VMs.
Exporting 10_1703_SYSPREP to C:\Virtual Machines\OVF\20180206 Exporting 10_1709_SYSPREP to C:\Virtual Machines\OVF\20180206 Exporting 7_X64_SYSPREP to C:\Virtual Machines\OVF\20180206 Exporting 7_X86_SYSPREP to C:\Virtual Machines\OVF\20180206 IMF32, Update CustomSettings.ini, 02/06/2018 11:55:56 IMF32, Cleanup MDT Monitoring data, 02/06/2018 11:55:57 IMF32, Show the OVFs, 02/06/2018 11:55:57 IMF32, OVF: C:\Virtual Machines\OVF\20180206\10_1703_SYSPREP\10_1703_SYSPREP.ovf, 02/06/2018 11:55:57 IMF32, OVF: C:\Virtual Machines\OVF\20180206\10_1709_SYSPREP\10_1709_SYSPREP.ovf, 02/06/2018 11:55:57 IMF32, OVF: C:\Virtual Machines\OVF\20180206\7_X64_SYSPREP\7_X64_SYSPREP.ovf, 02/06/2018 11:55:57 IMF32, OVF: C:\Virtual Machines\OVF\20180206\7_X86_SYSPREP\7_X86_SYSPREP.ovf, 02/06/2018 11:55:57 IMF32, The script took 0:Days 2:Hours 52:Minutes to complete., 02/06/2018 11:55:57
Today is one of the most exciting time in terms of technology and how it intervenes with our daily life. I strongly recommend embracing automation for image creation process due to the new way that Microsoft introduced to build, deploy, and service Windows: Windows as a Service. Windows 10 needs to be upgraded in a more frequent manner. By speaking of more frequently - you will need to deploy a new version of Windows every year, or optimally twice per year which is what I recommend for businesses in order to benefit from the new way Microsoft is building the OS in a long-term scope. This also implies that you will need to create new Windows 10 images on a regular basis.
The utopia of "click-and-go" image creation process that’s easy to maintain is here. Even better, all you need are free tools from Microsoft and one VMware Workstation license. By taking advantage of automation and by eliminating the drudgery of maintaining the machinery, you will reap rewards for many years to come