<< Back to Script Library

Clear Old SCCM Cache

Clears all content older than 7 days
Version: 1.1.7
Created: 2018-11-28
Modified: 2021-04-20
Creator: Rory.Monaghan
Downloads: 18
The Script Copy Script Copied to clipboard
        A simple script that clears all items older than 7 days in the SCCM update cache.
        Since Microsoft changed thier approach to Windows Updates, the size of the patches has increased significantly. This can be
        challenging to manage on persistent machines with limited disk space. This script is designed to clear that cache to free up
        some valuable disk space.
        The scrips perform a check to ensure the require COM object exists. If it does not exist, no action will be taken.
        For more information refer to:

        Stay in touch:

        C:\PS>\. ClearSCCMCache.ps1
  Clears SCCM Update cache items older than 7 days.

## Last modified 13:33 GMT 20/04/21 @rorymon

$resman = new-object -com "UIResource.UIResourceMgr"
$cacheInfo = $resman.GetCacheInfo()

if ($resman) {
$cacheinfo.GetCacheElements()  | 
where-object {$_.LastReferenceTime -lt (get-date).AddDays(-7)} | 
foreach {
} else {
write-host ("Required COM Object Does Not Exist. Ensure SCCM Client is Installed.")