Graeme Bray

Real World Automation and Deployment

MDT – Server 2012 R2 Pre-Capture Disk Cleanup

leave a comment »

As a result of going to TechEd, I learned a few disk cleaning techniques from Mikael Nystrom.  One of these was to run the following command during the Build & Capture Task Sequence.  This adds about 15 minutes on to the build time, but it can save (in my case) 700MB of space.  It may not end up being much, but in the server world, it can mean a lot.  (Disclosure, I have only tested on Server 2012 R2 U1)

Command: (Run Elevated) DISM.exe /online /cleanup-image /StartComponentCleanup /ResetBase

Used Space Before:



Used Space After:



I will shamelessly admit that I have taken one script from Mikael and edited them for use in my environment.  After all, why re-create something when there are already working examples?  I do leave all of the credit at the top of the script, so no issues there.

<job id=”Config-Server2012DiskCleanup”>
<script language=”VBScript” src=”..\..\scripts\ZTIUtility.vbs”/>
<script language=”VBScript”>
‘// Purpose: Used to Configure and reset the Base for Windows Server 2012 R2
‘// Usage: cscript Config-Server2012DiskCleanup.wsf [/debug:true]
‘// Version: 1.0 – 7 Sep 2011 – Mikael Nystrom
‘// This script is provided “AS IS” with no warranties, confers no rights and 
‘// is not supported by the authors or Deployment Artist. 
‘// Global constant and variable declarations
Option Explicit
Dim iRetVal
‘// End declarations
‘// Main routine
On Error Resume Next
iRetVal = ZTIProcess
ProcessResults iRetVal
On Error Goto 0
‘// Function: ZTIProcess()
‘// Input: None
‘// Return: Success – 0
‘// Failure – non-zero
‘// Purpose: Perform main ZTI processing
Function ZTIProcess()
Dim sCommand
Dim sConfigname
sConfigName = “Config-Server 2012 Disk Cleanup”
oLogging.CreateEntry sConfigName & “: Starting ” & sConfigName, LogTypeInfo

‘//Run a command
sCommand = “dism.exe /online /cleanup-image /startcomponentcleanup /resetbase”
oLogging.CreateEntry sConfigName & “: Running ” & sCommand, LogTypeInfo
iRetVal = oUtility.RunwithHeartbeat(sCommand)
oLogging.CreateEntry sConfigName & “: Return code from command = ” & iRetVal, LogTypeInfo

oLogging.CreateEntry sConfigName & “: Finished ” & sConfigName, LogTypeInfo
End Function


I will find a place to post the .wsf file online, but in the mean time, there it is


Written by Graeme

May 20, 2014 at 8:01 PM

Posted in Uncategorized

Tagged with

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: