Capture Windows Image using DISM – With Bells and Whistles

A little over a month ago (May 19th 2014) my friend Mikael Nyström wrote a blog article with an attached script that allowed you to capture a WIM / reference image using DISM instead of ImageX that MDT (Microsoft Deployment Toolkit) normally does. Making the switch improves capture time by 10-30 minutes based on my experience.

01-Copy-A-TaskSequence-Template

If you tried the script and found that your WIMs very “corrupt” is was related to a problem that now has been fixed by Mikael. I had one customer that had that problem without even knowing they had implemented this change – but after some struggle we found the cause of the problem and therefor I decided to write a blog post about how to implement this (awesome) change where it is a bit more clear that a change has been applied. Oh and the script-thing below is exactly what Mikael did and yes I have his blessings to “steal” the script. In order to save you some time, just go to his blog post (link above) and download the script from there, then just make sure to rename the script, update the class-name and the “things” with the template as I mention below. All credit for the brains about ditching ImageX in favour for DISM is all Mikaels.

As a side note, the customer noticed that their images were corrupt by a “permission” error during deployment of the image. Once we opened up the image we could see that the image (WIM file) contained the MININT folder and stuff like that. Stuff that should have been removed prior to the capture. Just as you can see in the image below.

Broken_Image

Howto Implements Changes to MDT

Start by creating a deployment share if you haven’t got one already that you can play with, ie a lab environment. I know you got one ;)

First create a copy of a Task Sequence template. If you are going to use this for server OS Deployment, take the server one and the client one for client OS deployment.

01-Copy-A-TaskSequence-Template

You find the template in the installation directory for Microsoft Deployment Toolkit, typically in C:\Program Files\Microsoft Deployment Toolkit\Templates.

02-TaskSequenceTemplateCopy

Rename it to something that you can remember, perhaps CompanyName-<Type>.xml, so we named it ConfigMgr101-Client.xml (ConfigMgr101 is my, Tim, demo company).

Now it’s time to do some editing. The UAC will prevent you from saving the file if you just simple open it up using notepad. Make sure to first start notepad in elevated mode and then open the file from within notepad.

03-Edit-TaskSequence-Template

Now, I don’t like using the built-in scripts when I make changes to stuff since they might be overwritten by an update and then I would loose all work. Therefor I go ahead and edit the created Task Sequence template on row 2, 192, 422 and 423. Use CRTL + G to go to a specific row number.

  • On row 2, change name=”Standard Client Task Sequence” :: TO :: name=”ConfigMgr101 Enhanced Client Task Sequence”
  • On row 192, change <action>cscript.exe “%SCRIPTROOT%\ZTIBackup.wsf”</action> :: TO :: <action>cscript.exe “%SCRIPTROOT%\ConfigMgr101ZTIBackup.wsf”</action>
  • On row 422, change <step name=”Create WIM” disable=”false” continueOnError=”false” successCodeList=”0 3010″ description=”” startIn=””>    :: TO ::      <step name=”Create WIM (Using DISM)” disable=”false” continueOnError=”false” successCodeList=”0 3010″ description=”” startIn=””>
  • On row 423, change <action>cscript.exe “%SCRIPTROOT%\ZTIBackup.wsf”</action> :: TO ::   <action>cscript.exe “%SCRIPTROOT%\ConfigMgr101ZTIBackup.wsf”</action>

See above for example.

Once we’ve saved the file we can actually directly see the new task sequence template when we look in the MDT console and try to create a new task sequence. It will however not work since there isn’t any ConfigMgr101ZTIBackup.wsf yet. Again, we could simply do it as Mikael did and replace the ZTIBackup.wsf and skip all of this, but then we need to fix the ZTIBackup.wsf if we ever update the MDT installation. Also, it’s harder to spot that something made a change ;)

04-Create-New-TaskSequence

05-Verify-Newly-Created-TaskSequence

Above we can again see that the changes have made it into a new task sequence created from the template. Yey! :)

 

Now comes the part where we really make the change. Locate ZTIBackup.wsf in the Scripts folder that you’ll find under C:\Program Files\Microsoft Deployment Toolkit\Templates\Distribution.

06-Copy-ZTIBackup

Rename it to THE SAME withing as you wrote in the template or it will not work. Also, it will not work if you put a dash (-) in the name. Keep it to A-Z and it will work.

09-sWimScriptPath

Above you see one of the last changes we’ll do. In order to keep this as simple as possible we’ll start from the bottom of the file. This is because we will add some new rows and that would mess up the row count.

On row 453 change: ( “imagex.exe”, sCmd )  :: TO :: ( “dism.exe”, sCmd )
On row 444 change so that it is commented out: sCmd = sCmd & ” /flags ” & oEnvironment.Item(“ImageFlags”) :: TO :: ‘ sCmd = sCmd & ” /flags ” & oEnvironment.Item(“ImageFlags”)
Comment out (a ‘ infront of the text on the row) row 435 and add new row below: sCmd = ” /capture /compress maximum ” & oDrive.Path & ” “”” & sBackupPath & “”” “”” & sPrefix & Left(oDrive.Path, 1) & “Drive”””
On row 436 (newly created): sCmd = ” /Capture-Image /CaptureDir:” & oDrive.Path & ”  /ImageFile:””” & sBackupPath & “””  /Name:””” & sPrefix & Left(oDrive.Path, 1) & “Drive”” /Compress:MAX /ConfigFile:””” & sWimScriptPath & “”””
On the empty row 434 add:  sWimScriptPath = oEnvironment.Item(“DeployRoot”) & “\Tools\” & oEnvironment.Item(“Architecture”) & “\wimscript.ini”
On row 431 comment it out and add a new row below: sCmd = ” /append ” & oDrive.Path & ” “”” & sBackupPath & “”” “”” & sPrefix & Left(oDrive.Path, 1) & “Drive”””
On row 432 add: sCmd = ” /Append-Image /CaptureDir:” & oDrive.Path & ” /ImageFile:””” & sBackupPath & “”” /Name:””” & sPrefix & Left(oDrive.Path, 1) & “Drive”” /ConfigFile:””” & sWimScriptPath & “”””
On the empty row 430 add: sWimScriptPath = oEnvironment.Item(“DeployRoot”) & “\Tools\” & oEnvironment.Item(“Architecture”) & “\wimscript.ini”
On row 81: Add a new row below it
On row 82 (newly created) add: Dim sWimScriptPath

Does it sound hard? Take a closer look at the image below.

08-Capture-Image

07-NamingTheFile

Finally at the top of the script, change the Class row to reflext the name of the script file except the dot and the file ending.

Save the file and you are done!

 

/Tim

m4s0n501

About The Author

Tim Nilimaa is a consultant with Lumagate in Sweden. He has been working with Configuration Manager for 8 years. His knowledge has been selected as a speaker at many events among them Microsoft Management Summit.

No Comments

Leave A Reply