Use DISM to cleanup WinSxS after Windows Update

After making a reference image of a Windows 8.1 installation and updating it, we wanted to clean up the installation. There are a few methods that can be used, such as using Disk Cleanup GUI and select Windows Update Cleanup, or run the StartComponentCleanup (found under MicrosoftWindowsServicing) in Task Scheduler but using the CLI to achieve this is much cooler and you have stronger options.

102314_1557_UseDISMtocl1

As shown in the picture, we have updated the computer with all latest patches with PowerShell, see my previous post. And after no more updates are available we used DISM to clean up everything. Here I will show 3 options to clean up the system:

This option is the same as using the Task Scheduler method, but now the updated components are immediately deleted. If had used the task, it will only clean up if the updated components are longer then 30 days installed on the system.

This one is my favorite to use after installing a new system. The /ResetBase switch option also deletes all superseded versions of every component in the component store. A warning if you want to use it on systems in production: All existing service packs and updates cannot be uninstalled after this command is completed. But this option will not block the uninstallation of service packs or updates installed later on.

This one is useful after installing a service pack on your system. The /SPSuperseded switch option removes all backup components needed to uninstall the service pack. Also a sidenote here, you cannot remove the service pack anymore after using this command.

Of course, there are more options possible with DISM and maybe you need to change the switch options a bit, here is the help output for /Cleanup-Image:

Update: Windows 10 build 10547 output of the DISM /Cleanup-Image command:

It looks like only the version number is altered and that the same commands can be used in Windows 10.

  • Giulia

    what about windows 10

    • BVucinec

      The same commands can be used on Windows 10, just tested it on build 10547 with the command “dism /online /cleanup-image /startcomponentcleanup /resetbase”
      I’ve updated the post with the Windows 10 version of the command.

  • Graeme Gibbons

    stuck on blue screen automatic repair preparing your desktop loop cannot access desktop can i use dism from winpese enviroment to repair this i have win 10 iso what commands should i use
    graeme