SCCM cache clear script

C:\Windows\ccmcache

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


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

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

Leave a Reply

Your email address will not be published. Required fields are marked *