Capture multiple images using one MDT task sequence

Note: This blogpost is also posted on my personal blog – https://itmicah.wordpress.com.

If you deploy images in your environment that are very similar, meaning one has a few more applications installed than the other, then this is the blogpost for you! In this blogpost I’m going to share a script with you that will allow you to capture multiple images in one WIM file using only one MDT task sequence. Sound good? Let’s get cracking! 

Here’s the scenario: a company has two types of clients:

  • FAT client
    PC with Win7 OS, Office 2010 and other locally available apps
  • Terminal client
    PC with Win7 OS only. Uses a client to connect to a virtual desktop directly.

The FAT client’s image is at it’s core the same as the Terminal image. The only difference is that it has more applications installed. Also, since the FAT image contains an MS Office installation the image will also contain more WSUS updates to patch the Office applications.

TSCapture-Standard

Standard Capture section in a client Task Sequence

In order to maintain these images MDT (Microsoft Deployment Toolkit) comes in play. It has all the tools you need to create and maintain images. In a standard MDT client task sequence you can:

  • Install a Windows operating system, injected with the appropriate drivers
  • Install applications and middle ware (DotNet, Visual C++ Redist, etc.)
  • Install (WSUS) updates
  • Capture the image in a .WIM file

With the standard MDT setup you’d have to create two task sequences to capture both images. This means you’d have to install the operating system twice, which is an inefficient use of time, and you usually end up with two separate .wim files, which is an inefficient use of storage space. In order to create a more efficient approach you have to understand how the capture part of the task sequence works.

The MDT capture process

When MDT is done installing the operating system, the applications and updates, it will check if the task sequence variable DoCapture is set to yes. This can be done by editing the CustomSettings.ini, the MDT database or by setting the variable in the Task sequence directly. If the variable is indeed set to yes the Capture Image part of the task sequence will execute. The first step is to apply the PE image to the hard drive. The wim file is copied over to the local hard disk. When this process is finished sysprep is run to generalize the image for capture. Then the BCD is set up to boot into the local PE environment. After a reboot the computer is now back where it all started: Windows PE!

Because our deployed image is now offline it can be captured in a wim file. For this it uses the following Task sequence variables:

  • ComputerBackupLocation=NETWORK
    This will enable you to save the image in a file on a network location
  • BackupShare=\\SRV-MDT-001\DeploymentShare$
    This is the network location where we’ll save the image, usually the MDT deploymentshare.
  • BackupDir=Captures
    The directory the image file will be stored. The Captures folder on the deploymentshare is there for this very purpose. Just make sure you have write access to this folder with your MDT user credentials.
  • BackupFile=FAT_Terminal.wim
    This is the name of our image file. As you can see the name I’ve chosen indicates that my wim file will contain both FAT and Terminal client images.

When the capture is completed the task sequence is complete. There are no more steps visible in your MDT console, but in the background the cleanup script is restoring the boot to the local OS, removing files left over from the deployment and other stuff to ensure a clean end product.

Continue after capture

In order to continue the task sequence after capturing an image I created a script called LTIRestoreBoot.wsf. I’m not a master in vbscript (PowerShell is my game) so I borrowed a few sections from the LTICleanup.wsf script and altered them slightly to do my bidding. The script completes the following tasks:

  • Removes the local PE environment we mentioned earlier
  • Restores the BCD so after a reboot we’ll boot into the local OS
  • Copies the unattend file to the windows\panther folder without altering it
  • Copies the LTIBootstrap.vbs file to the root of the local drive so the task sequence will continue after the reboot
  • Clears the BootDrive task sequence variable set by the LTIApply script’s first run. If we don’t deal with this step, the second time the script is run it’ll try to use the system partition to apply the boot image

The script is available on my Github. Download it and drop it into your Scripts folder in your MDT deployment share. This is how you use it in the task sequence:

  • Create a Set Task Sequence Variable task right before the Create WIM task. Change the name to Set image name and use the following settings:
    • Task Sequence Variable:
      TaskSequenceID
    • Value:
      TerminalImage (or any other name you'd like)

    The reason for this step is that the ZTIBackup script uses the TaskSequenceID variable to name the image in the wim file.

  • Create another Set Task Sequence Variable task right after the Create WIM task. Change the name to Restore TaskSequenceID variable and use the following settings:
    • Task Sequence Variable:
      TaskSequenceID
    • Value:
      Whatever your TaskSequenceID was originally called
  • Create a Run Command Line task, name it Restore Boot to OS and use the following settings:
    • Command line:
      cscript.exe "%SCRIPTROOT%\LTIRestoreBoot.wsf"
    • Start in:
      %SCRIPTROOT%
  • Create a Restart computer task (or copy/paste the previous one).
  • Add the tasks you want to run in the second image (like installing applications and updates). Make sure you start with a Gather task.
  • Copy the Capture Image folder (or group) and paste it after the previous tasks. Alter the Value in the Set image name task to reflect the second image. I’ve named it FATImage.
  • Remove the tasks Restore Boot to OS and Restart Computer from the copied folder.

Your task sequence should look similar to this (tasks preceding the first capture section have been left out of the image):

Task sequence after the changes

As you can see I’ve created some extra folders to make everything more readable. The end result after running our new task sequence is a single image file (WIM file) which contains two images: TerminalImage and FATImage. You can import this new WIM file in MDT and test the deployment. The ZTIBackup script automatically appends the second image to the existing WIM file on a seperate index. This has the added bonus that by consolidating two similar images in a single WIM file you’re utilizing Single-Instance Storage. This is the ability to remove file duplication to optimize storage capacity. You can read all about it on this TechNet page:

https://technet.microsoft.com/en-us/library/ee914607.aspx

That’s it! If you have any questions please let me know. If this post has been useful to you drop me a line in the comments.

MicaH

2 replies
  1. Wesley Esterline
    Wesley Esterline says:

    This is an amazing blog! Thank you so much for your write ups, including the script to recreate NetConnectionProfile commands in Power Shell on Windows 7. Super helpful! Keep up the great work.

    Reply

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *