Nice to Know – Get rid of all junk before Sysprep and Capture when creating a reference image in MDT
Posted by Mikael Nystrom on June 5, 2014
I can see a lot of comments about different versions and issues. Just to clarify, we use this script with the legacy version of Windows up to Windows Server 2016 (build 1607) and Windows 10 (build 1607). We have no issues with adding .NET Framework, since we do that before cleaning. We also have no issues adding anything else. There are some comments about “it takes time”, yes it does. Also, the script is “live”, that means that it will be a new version now and then. For the exact version and changes, please check GitHub.
I have updated the script once more, current version is now 2.4
There have been som issues with W8.1 and WS2012 R2 and it turns out that installling patches will allways make the component store “broken”. There seems to be a patch that mess it up. The fix is to run a repair of the store before compressing it. The script will now do that.
The script did not recognice som operating system version and/or the log file did output incorrect information. The script now works with Windows 7 SP1 – Windows 10 and Windows Server 2008 R2 – Windows server 2016 TP4 (including Core editions).
I relalized that there is no reason to keep the downlod patch cache, so that is now deleted in a correct way before capture. If you would like to keep that WSUS Client Cahce, open the script and remove the secion for each OS that does that part.
The script now uses a function that will popup the command windows so you can see the progress and if it gets stuck, it takes time to run it. The mopst important thing to remember is to reboot before you run the script, since all patches must be installed correctly, in some cases that might need to reboots, since a few patches doers require that (should not, but…)
When you create a reference Image it will in most cases it will be updated with patches and some more patches and then some… That will make the image bigger and therefore the deployment of that image will take longer and consume more network resources. That can be corrected by getting rid of superseded patches, junk, temp files and much more. MDT does take care of much using the wimscript.ini during the capture process, but not all, not the old updates among other things.
Since MDT is the preferred method to create reference images you can download the script, import it as an application and then run the application just before the Sysprep and Capture step. The Script works for the following versions of Windows:
- Windows 7 SP1
- Windows 8
- Windows 8.1 Update 1
- Windows 10
- Windows Server 2008 2 SP1
- Windows Server 2012
- Windows Server 2012 R2
- Windows Server 2016 TP 4
However, to make this work in Windows 7 and Windows Server 2008 R2 you need to add a hotfix to Packages in MDT. http://support.microsoft.com/kb/2852386
The script will use clenmgr.exe in all client versions of Windows. In Windows Server 2008 R2 it also uses clenmgr.exe, but it is never installed, instead it is copied from the SXS folder, that way we don’t need to install Desktop Experience. On Windows 8, Windows 10 and Server 2012 the script also runs the dism /online /clenup-image /startcomponentclenup and on 8.1 and server 2012 R2 the script adds the /Resetbase to make it impossible to remove patches.
Step By Step (kind of)
Download the script
Download the script from here http://1drv.ms/ThvLFE
Download the NEW Script from here: https://onedrive.live.com/?id=8563304F134DDCB6%211162216&cid=8563304F134DDCB6&group=0
Import it in MDT
Open the Deployment Workbench and browse to the Application node and import the folder you downloaded, giver it a name and as command line you type:
Modify the Task Sequence
Open your task sequence and before the Sysprep and capture step, something like this works fine.
Add the HotFix (only for Windows 7 SP1 and Windows Server 2008 R2)
You need to add the patches in the deployment workbench. If you would like the deployment of the reference image to a bit faster, create three folders put the correct patch in each folder and then create corresponding Selection Profiles and modify the Task Sequence to use them. You download the update here http://support.microsoft.com/kb/2852386
Here you can see the patches imported in the Deployment Workbench.
Here you can see the Selection Profiles and the selection in one of them.
Here you can see how the modification in the Task Sequence.