Cleaning Up Windows SxS Folder in Preparation for Imaging

windows-server-core dism features-on-demand windows-server-2012

In preparation for releasing an operating system image to be used as a VM template, I usually like to perform some “shrinking commands” to make sure the image has as small a footprint as possible.

All the “shrinking commands” are command-line or PowerShell-based because they must also be able to be performed on a Windows Server Core installation.

Remove all Uninstalled Feature Binaries

The first thing I usually do is remove any uninstalled feature binaries (as part of Windows Features on Demand). I’ve covered this in an earlier article here.

Remove Old Service Pack Backup Files

The following command removes any files that were backed up as part of installing a service pack. If you execute this command, you won’t be able to uninstall any service packs.

DISM /online /cleanup-image /SPSuperseded

DISM /online /cleanup-image /SPSuperseded
DISM /online /cleanup-image /SPSuperseded

Remove Superseded Components

This command removes any components in the Windows SxS folder that have been superseded by newer versions.

For Windows Server 2008/2008 R2/2012 and Windows 7/8:

DISM /online /cleanup-image /StartComponentCleanup

For Windows Server 2012 R2 and Windows 8.1 (performs some additional optimization):

DISM /online /cleanup-image /StartComponentCleanup /ResetBase

DISM /online /cleanup-image /StartComponentCleanup /ResetBase

DISM /online /cleanup-image /StartComponentCleanup /ResetBase