CI – Cleanup CCMcache

When I was at the MMS this year, I asked the Microsoft product team if the CCMCache is OK to clean up, because a lot of files is in the folder, and there is no built-in to do so.

This is a standard Configuration Item, pretty easy when you get into it.

Let say, we want to delete all content in C:\Windows\ccmcache if its 60 days or older.

Discovery script:

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

Like this:
2017-09-18 13_44_52-sql.invidjkp.local - ASG-RemoteDesktop 2017 - invjkp-sccm03.png

If i just test this on a machine. It gonna look like this
2017-09-18 13_40_59-sql.invidjkp.local - ASG-RemoteDesktop 2017 - SCCM02.png

The result is the number of files that are older than 60 days.

Remediation script:

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

Like this:
2017-09-18 13_50_55-sql.invidjkp.local - ASG-RemoteDesktop 2017 - invjkp-sccm03.png

Compliance rule:
2017-09-18 13_52_42-sql.invidjkp.local - ASG-RemoteDesktop 2017 - invjkp-sccm03.png

Deploy this to some machines that you want to clean up, And you are good to go.

/Pontus

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s