SCCM clean client cache script (ccmhache cleanup)

SCCM clean client cache script (ccmhache cleanup). You are probably already aware that SCCM manages its client cache pretty well (delete older objects when free space end).

This script is purge all content in the ccmcache folder that is older than X days. Work with any SCCM release (tested with 1706).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()

You might also like

Leave a Reply

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More