Chotaire Wiki

Stuff you didn't know

User Tools

Site Tools


windows-server-2019-remove-unused-features

Remove unused features and roles from Windows Server 2019 component store

By default, on Windows 10 and Windows Server 2019 all features and roles are copied to disk even if they are not installed. This allows for fast role and feature installations and consistent patching. To reduce the footprint of your Windows installation, all unused features can be removed from component store.

Windows 2019 / Hyper-V 2019: Removal using Powershell

Uninstall all roles and features that are not currently in use. First, we need powershell which needs to be run as administrator.

Get-WindowsFeature | Where-Object {$_.Installed -match "False"} | Uninstall-WindowsFeature -Remove

Windows 10: Removal using DISM

Eventhough it has worked for many years, the /remove option is currently being ignored on Windows 10, primarily to ensure that the Reset/Refresh functionality works as expected. Hopefully this option will get re-added to be able to remove bloat from the component store. Thereby, the removal as mentioned below does not currently work.

The equivalent for Windows 10 looks different as it cannot be done using PowerShell. Instead use cmd.exe as an Administrator and try:

for /f %a in ('dism /online /get-features /format:table ^|find "| Disabled"') do (dism /online /disable-feature:%a /remove)

Note that the get-features table is localized. So if you use e.g. a German version of Windows 10, replace “Disabled” with “Deaktiviert” for this command to actually remove features. To double-check, display the table first:

dism /online /get-features /format:table

Disk Cleanup

Up next, the following command is typed into a cmd.exe shell, also run as Administrator. When able to select, why not just clean everything. As a minimum, you should clean Windows updates. Why? This will shrink the WinSxS store after you have removed unused roles and features.

cleanmgr

Instead of using DISM first, we needed to do this using cleanmgr, because every once in a while DISM fails to reassemble the WinSxS store and will refuse to do so until after the next batch of windows updates.

Use DISM to clean WinSxS

Now that you have used cleanmgr first, let's go and do another WinSxS cleanup using DISM to get rid of actual Windows updates from the past 30 days. It will go pretty fast after having run cleanmgr so this is a good chance to do it. Check out this article for more info about DISM to clean your Windows installation: Windows 10: Clean up the WinSxS folder

Dism.exe /online /Cleanup-Image /StartComponentCleanup /ResetBase

Disk Defragmentation

To put the cherry on top (regardless if you are using a harddrive or a SSD) run Disk Defragmentation now. But shouldn't we be doing this on a SSD, that's what everyone is screaming? Well, when detecting an SSD, the Windows 10 built-in Disk Defragmentation tool will simply trim the SSD instead of defragmenting it, so it keeps your SSD running fast. If this is a VM, make sure that your virtual harddrive is emulated as SSD in your VM settings. On KVM and VirtualBox 6 virtual machines, trimming a virtual SSD can send discards to the host filesystem (such as Thin-LVM or zfs), thus decreasing the size of your thin-provisioned volume, if your VM has been configured to support this.

Sdelete will zero unused blocks

That's it. You have just saved more than 4GB of diskspace for removed roles and features alone. Since you also deleted a whole bunch of old Windows updates, this might well go into the 10-20GB of saved diskspace. If this is a VM not running on a thin-provisioned filesystem with “discard” option (such as when using older versions of VirtualBox), you might want to zero unused blocks from your disk using Sysinternals sdelete. Replace c: with whatever drive letter you use.

sdelete64 -z c:

Hint: VirtualBox users should then shut down the VM (wait until it is shut down or you would destroy the VM disk) and issue on the host: vboxmanage modifymedium –compact /path/to/thedisk.vdi



windows-server-2019-remove-unused-features.txt · Last modified: 2019/09/25 03:59 by chotaire