Pages

Followers

Safe cleaning up WinSXS folder in Windows Server

Safe cleaning up WinSXS folder in Windows Server 2012

Before talking about safe cleaning up WinSXS Folder in Windows server 2012 let’s try to understand what is WinSXS folder, what is saved in this folder, and why its size is constantly increasing in course of time.
[accordion]
[tab title=”Contents of this article”]

If you remember during installation of additional features in Windows Server 2003 the installation wizard demanded to put installation disk in CD-Rom or to show the way to the catalogue with Windows Server 2003 installation package. Microsoft decided to change its policy for Windows additional roles and feautures in Windows Server 2008. Now all binary files which are necessary for any role roll-out are stored in folder %windir%WinSxS (WinSxS – Windows Side By Side). This means that in case of any additional role installation there is no need to search and connect the disk with installation package to the server. Of course in case of such attitude much more space is needed for OS. It is necessary to understand that system key components are located in WinSXS catalogue and it is not allowed to delete anything from it manually by no means. Why is it constantly increasing in size? The answer is simple – updates. During installation of updates for different features in WinSXS catalogue the old and the new version of the updated feature is saved. Due to such architecture we can safely delete any installed update at any time and return to the old version of the feature.
And what should one do if the system is launched and works well, there is no need in additional roles rollout but it is still not enough space on disk? It seems quite illogical that several gigabytes on system disk are taken for installation packages which will never be needed! Unfortunately, it’s rather difficult to delete these files without any system damage in Windows Server 2008. However Microsoft in the new server OS (Windows Server 2012) decided to improve this disadvantage by implementation of a new function which is called Features on Demand.

Features on Demand in Windows Server 2012

Features on Demand function allows to decrease space on disk which is taken for system files due to possibility of unused roles binary files deletion from WinSxS folder. In case when later on there will be a necessity to return a previously deleted role all necessary files can be found in Windows Server 2012 installation package image, Windows Update service or network resource with the original content.
With a help of the following Powershell command you can get information about all system roles and features:
1
Get-WindowsFeature
As you can see the state of every role is displayed in Install State column. Such states are possible:
  • Installed: the role or the feature is installed and is used by the system at the moment
  • Available: the role is not installed on the server, however all necessary files are available on disk, which allow to install/ activate this role at any moment.
  • Removed: the role or feature is not installed on the server, all files necessary for its installation are removed from disk
Correspondingly, in case of any role installation via GUI or Powershell (Install-WindowsFeature command) its state will be changed from Available to Installed or in case of deletion(Uninstall-WindowsFeature command) and vice versa .

Deleting unused roles from Windows Server 2012

Role deletion from disk (from WinSxS folder) is possible only via Powershell. Special command argument Uninstall-WindowsFeature –Remove should be used for this purpose.
If you need to delete DHCP server role binary files for example the following command should be used:
1
Uninstall-WindowsFeature –Name DHCP –Remove

The following command will delete Active Directory Domain Services catalogues service files:
1
Uninstall-WindowsFeature AD-Domain-Services -Remove

With a help of Powershell it is possible to write even more complicated command which will delete all installation files of Windows Server unused roles and functions:
1
Get-WindowsFeature | Where-Object {$_.InstallState -Eq “Available”} | Uninstall-WindowsFeature -Remove
In our example, providing that only one file-server role was installed, the size of WinSxS folder will decrease from 8 to 5 Gb. It is not a bad result, isn`t it? Even more so, we used only one command for WinSxS folder cleaning up.

How install deleted roles and features in Windows Server 2012

One more example, let’s assume that you need to install some Windows Server 2012 role, but it`s installation package is deleted from WinSxS catalogue. It is possible to recover this role in several ways: with a help of GUI Server Manager or with a help of Powershell.
Before you start role files recovery it is necessary to define the index of Windows Server 2012 installed edition. We need disk with Windows Server 2012 installation package (install.wim image file to be exact which is allocated in sources catalogue). Perform the following Powershell command:
1
Get-windowsimage –imagepath <path_to_wim_file>sourcesinstall.wim
Please find the version of Windows Server which is installed on your PC and remember its index ( the value in the Index line) In our example it’s Windows Server 2012 Datacenter with index 4.
The same operation can be performed with a help of Dism utility:
1
dism.exe /get-imageinfo /imagefile:d:sourcesinstall.wim

Installing removed role by using Server Manager

Open the Server Manager console and enable the role installation Manager (Add Roles and Features). Select role or feature which is needed to be installed. The Manager will warn you that some files which are needed for this role installation are missing and you have to specify an alternate source path to installation package location. Press Specify an alternate source path button.

In Path field specify full path to intall.wim file and OS installed edition index in the following format:
1
WIM:D:SourcesInstall.wim:4
After the OK button is pressed all files necessary for the installable role will be copied to WinSxS catalogue.
If it is needed the path to the catalogue with WIM file or network path to the WinSxS catalogue may be specified in this line. Besides, it is possible to specify the path to this catalogue for the group of servers with a help of group policy ( Computer Configuration / Administrative Templates / System / Specify settings for optional component installation and component repair). The last variant is very convenient if it is needed to perform plenty of server installations with Windows Server 2012 because the total effect of  such cleaning may lead up to hundreds gigabytes.

gpo windows 2012 component install path

Windows Server 2012 recover deleted roles with Powershell

The same operation can be performed with a help of only one Powershell command. Let’s assume we need to recover ADDS role remote files. Let’s perform the following command:
1
Install-WindowsFeature AD-Domain-Services -Source WIM:WIM:D:SourcesInstall.wim:4
So in this article we learned with a new Windows Server 2012 function which is called Features on Demand it allows to delete binary files with server roles installation packages from WinSxS catalogue. The deleted role can be recovered if it is needed: all you need is Windows Server 2012 installation package.
Feature on Demand in Windows 8 works a little bit differently, this is because Powershell command let which we have used in previous cases simply doesn`t exist here. DISM command with /Disable-Feature parameter  is considered to be its analogue (not so convenient).WinSxS directory contents can also be compressed more about this in the article: How to Clean Up and Compress WinSxS Folder.
  Tip. Мore about reducing  size of the WinSxS folder in Windows 8.1 here