After machines have been running for some time without a reimage, the WINSXS can fill up due to many updates that need cleaning out.
The WINSXS folder is a repository for updates that have been installed to allow for removal. However, cumulative updates can weigh down on disk space, storing all these removal points. When running an extensive network of machines, PSEXEC is king for running these sorts of commands.
There are two ways to clean out the WINSXS folder; one is more aggressive than the other. Both will need you to run as an administrator account on the remote machine. There is no need to run both commands in each example; one is if your command prompt user has access, and the 2nd is to use a particular user in each example.
StartComponentCleanup task in Task Scheduler to clean up and compress components
psexec @computers.txt -c schtasks.exe /Run /TN "\Microsoft\Windows\Servicing\StartComponentCleanup"
psexec @computers.txt -u machineadmin -p -c schtasks.exe /Run /TN "\Microsoft\Windows\Servicing\StartComponentCleanup"
The next method is more aggressive and will yield better space clearing.
DISM
Using the /ResetBase parameter and /StartComponentCleanup parameter of DISM.exe on a running version of Windows 10/Server 2016 or later removes all superseded versions of every component in the component store.
psexec @computers.txt DISM /online /Cleanup-Image /StartComponentCleanup /ResetBase
psexec @computers.txt -u machineadmin -p DISM /online /Cleanup-Image /StartComponentCleanup /ResetBase
The script above is from MS tech articles on the internet and has been modified for our use. It comes with no warranty.