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:

dism /online /Cleanup-Image /StartComponentCleanup

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.

dism /online /Cleanup-Image /StartComponentCleanup /ResetBase

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.

dism /online /Cleanup-Image /SPSuperseded

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:

Deployment Image Servicing and Management tool
Version: 6.3.9600.17031

Image Version: 6.3.9600.17031


/Cleanup-Image /RevertPendingActions

  WARNING! You should use the /RevertPendingActions option only in a
  system-recovery scenario to perform recovery operations on a Windows image
  that did not boot.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /RevertPendingActions

/Cleanup-Image /spsuperseded [/hidesp]
  Use /SPSuperseded to remove any backup files created during the installation
  of a service pack. Use /HideSP to prevent the service pack from being listed
  in the Installed Updates for the operating system.

  WARNING! The service pack cannot be uninstalled after the /SPSuperseded
  operation is completed.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /spsuperseded /hidesp

/Cleanup-Image {/CheckHealth | /ScanHealth | /RestoreHealth}
  Use /CheckHealth to check whether the image has been flagged as corrupted
  by a failed process and whether the corruption can be repaired.
  Use /ScanHealth to scan the image for component store corruption.
  Use /RestoreHealth to scan the image for component store corruption, and
  then perform repair operations automatically.
  Use /Source with /RestoreHealth to specify the location of known good
  versions of files that can be used for the repair. For more information on
  specifying a source location, see
  http://go.microsoft.com/fwlink/?LinkId=243077.
  Use /LimitAccess to prevent DISM from contacting WU/WSUS.

    Example:
      DISM.exe /Online /Cleanup-Image /ScanHealth

      DISM.exe /Image:c:offline /Cleanup-Image /RestoreHealth
      /Source:c:testmount

/Cleanup-Image /StartComponentCleanup [/ResetBase]
  Use /StartComponentCleanup to clean up the superseded components and reduce
  the size of the component store. Use /ResetBase to reset the base of
  superseded components, which can further reduce the component store size.

  WARNING!  The installed Windows Updates cannot be uninstalled after the
  /StartComponentCleanup with /ResetBase operation is completed.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /StartComponentCleanup

/Cleanup-Image /AnalyzeComponentStore
  Use /AnalyzeComponentStore to create a report of the WinSxS component store.
  For more information about the WinSxS report and how to use the information
  provided in the report, see
  http://go.microsoft.com/fwlink/?LinkId=293367.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /AnalyzeComponentStore

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

Deployment Image Servicing and Management tool
Version: 10.0.10547.0

Image Version: 10.0.10547.0


/Cleanup-Image /RevertPendingActions

  WARNING! You should use the /RevertPendingActions option only in a
  system-recovery scenario to perform recovery operations on a Windows image
  that did not boot.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /RevertPendingActions

/Cleanup-Image /spsuperseded [/hidesp]
  Use /SPSuperseded to remove any backup files created during the installation
  of a service pack. Use /HideSP to prevent the service pack from being listed
  in the Installed Updates for the operating system.

  WARNING! The service pack cannot be uninstalled after the /SPSuperseded
  operation is completed.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /spsuperseded /hidesp

/Cleanup-Image {/CheckHealth | /ScanHealth | /RestoreHealth}
  Use /CheckHealth to check whether the image has been flagged as corrupted
  by a failed process and whether the corruption can be repaired.
  Use /ScanHealth to scan the image for component store corruption.
  Use /RestoreHealth to scan the image for component store corruption, and
  then perform repair operations automatically.
  Use /Source with /RestoreHealth to specify the location of known good
  versions of files that can be used for the repair. For more information on
  specifying a source location, see
  http://go.microsoft.com/fwlink/?LinkId=243077.
  Use /LimitAccess to prevent DISM from contacting WU/WSUS.

    Example:
      DISM.exe /Online /Cleanup-Image /ScanHealth

      DISM.exe /Image:c:offline /Cleanup-Image /RestoreHealth
      /Source:c:testmount

/Cleanup-Image /StartComponentCleanup [/ResetBase]
  Use /StartComponentCleanup to clean up the superseded components and reduce
  the size of the component store. Use /ResetBase to reset the base of
  superseded components, which can further reduce the component store size.

  WARNING!  The installed Windows Updates cannot be uninstalled after the
  /StartComponentCleanup with /ResetBase operation is completed.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /StartComponentCleanup

/Cleanup-Image /AnalyzeComponentStore
  Use /AnalyzeComponentStore to create a report of the WinSxS component store.
  For more information about the WinSxS report and how to use the information
  provided in the report, see
  http://go.microsoft.com/fwlink/?LinkId=293367.

    Example:
      DISM.exe /Image:C:testoffline /Cleanup-Image /AnalyzeComponentStore

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

Branko Vucinec

About Branko Vucinec

Hi! I'm Branko, a Systems Engineer focused on Microsoft technologies from the Netherlands. I enjoy helping organizations with the business and people opportunities and challenges surrounding tech.

Comments