Cleaning Up Windows SxS Folder in Preparation for Imaging

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

All the “shrinking commands” are all 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 Superceeded Components

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

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

DISM /online /cleanup-image /StartComponentCleanup

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

Remove all Uninstalled Feature Binaries

I’m still getting my head around this whole blog thing, but I’m going to write a quick article about trimming down a Windows Server 2012 install while I wait for my partner to recover from a small bout of vertigo.

The “Features on Demand” feature of Windows Server 2012 is really great at trimming down a Windows Server 2012 installation.

To use the “Features on Demand” you need to “remove” the binaries required by any features that aren’t currently installed by your OS. You can remove them one by one, but this is a real drag.

The following command will remove the binaries for any non-installed features on your system:

get-windowsfeature | where-object -FilterScript { $_.InstallState -eq 'Available' } | remove-windowsfeature -remove
Features on Demand Removal Progress

Features on Demand Removal Progress

Features on Demand Removal Complete

Features on Demand Removal Complete

After you’ve run this command you’ll need to have your windows install source available if you want to install any additional features. You might also need to specify an alternate source location when installing any future features. For more information on installing windows features from an alternate source, see this article on TechNet:

Install or Uninstall Roles, Role Services, or Features

I usually like to run this command when I’m preparing a new VM template after I’ve installed all the features I think will be needed for this VM. This results in a smaller deployment footprint.

Installing Windows Server 2012 R2 Core – Additional Tools and Scripts

Although Windows Server Core is a great way of ending up with a slim and trim diet server, it can be a little bit tricky when first getting started configuring it. During my experiments running Server Core VM’s I found that there were a few tools either built into server core or available separately that can help get over this configuration “hump”.

Built-in Tools

  1. SConfig.exe

    SConfig.exe is a built in command line tool (with a simple command line GUI) that allows you to perform some simple configuration tasks on your core installation.

    SConfig.exe

    SConfig.exe

    Some of the functions include:

    1. Renaming the computer
    2. Joining a domain or workgroup
    3. Enabling remote management (Win-RM)
    4. Enabling remote desktop
    5. Installing windows updates
    6. Configure network settings
    7. Change system date/time
    8. Shutdown/reboot server

Other Tools

When installing a new copy of one of the Windows Server Core versions it’s quite useful to install several additional tools that will help manage the server from a command prompt and/or PowerShell console.

  1. Corefig for Windows Server 2012 Core and Hyper-V Server 2012

    Corefig allows you to configure some of the main settings of a Windows Server Core installation as well as installing updates and windows features and roles.

    Corefig PowerShell Application

    Corefig PowerShell Application

  2. Windows Update PowerShell Module

    The Windows Update PowerShell module allows you to install windows updates from a PowerShell command line by executing (after installing the module onto the server):

    Get-WUInstall
  3. Remote Server Administration Tools PowerShell module

    The Remote Server Administration Tools PowerShell module is available as an installable feature on Windows Server Core edition. It needs to be first installed by executing the following command at a PowerShell prompt:

    Add-WindowsFeature -Name 'RSAT-AD-PowerShell' -IncludeAllSubFeature
  4. PowerShell Community Extensions

    The PowerShell Community Extensions project provides various useful PowerShell cmdlets. I always install this onto the server and copy the entire PSCX modules folder:

    c:\Program Files (x86)\PowerShell Community Extensions\Pscx3\

    folder into the system modules folder:

    c:\Program Files\WindowsPowerShell\Modules

    This makes the PSCX module available by the import-module command in PowerShell.