You are probably already aware that SCCM manages its client cache pretty well (delete older objects when free space end). I’ve run into situations where PC has less disk space on the system drive than desired, so I get a compliance settings rule scripts that will help keep the cache a little more tidy.

This script is an example to purge all content in the ccmcache folder that is older than X days. Perfectly work with SCCM 1610. Below the code for compliance rule.

$MinDays = 20
$UIResourceMgr = New-Object -com “UIResource.UIResourceMgr”
$Cache = $UIResourceMgr.GetCacheInfo()
($Cache.GetCacheElements() |
where-object {[datetime]$_.LastReferenceTime -lt (get-date).adddays(-$mindays)} |

$MinDays = 20
$UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
$Cache = $UIResourceMgr.GetCacheInfo()
$Cache.GetCacheElements() |
where-object {[datetime]$_.LastReferenceTime -lt (get-date).adddays(-$mindays)} |
foreach {

P. S. Alarm! You may get error in report if you don’t set powershell execution policy “Bypass” in Default Client Settings\Computer Agent.

P. S. S. Script only clear cache that in the client list. If you upgarde or reinstall sccm client on client pc you see that not all folders in c:\windows\ccmcache persist in cache list. In this situation you need another script to clear folder.

Get the list of ccmcache objects run ps script:

$CMObject = New-Object -ComObject “UIResource.UIResourceMgr”
$CMCacheObjects = $CMObject.GetCacheInfo()

Thanks to Greg’s Systems Management Blog for script.