Skip to content

November 17, 2015

Clear SCCM Cache by Deploying a Package

A while back, I wrote a simple PowerShell script that will clear the cache on a SCCM client machine (I will post this script for your reference at the end of this blog).

I mostly used this script during a large Task Sequences (ie. during a build and capture task sequence that installs a lot of software), since the cache would fill completely and then fail the Task Sequences (it appears that SCCM will not override any items in cache during the task sequence). This never presented an issue since I always ran the script directly from the Distribution Point.

However, there is one caveat when executing this script by deploying a SCCM package. It is important that when you deploy the package to use the “Run from Distribution Point” option. If you do not do this, the script will fail. This is because it will be running from the cache that you are trying to clear.

Here is the script I use:

Example Usage to use with SCCM Program: powershell.exe -Command “.\ClearConfigMgrCache.ps1 -DeletePersistent $true”

 [bool] $DeletePersistent
$CMObject = New-Object -ComObject "UIResource.UIResourceMgr"
$CMCacheObjects = $CMObject.GetCacheInfo()
$CMCacheElements = $CMCacheObjects.GetCacheElements()
foreach ($CMCacheElement in $CMCacheElements)
    if ($DeletePersistent -eq $true)
        $CMCacheObjects.DeleteCacheElementEx($CMCacheElement.CacheElementId, $true)

Share your thoughts, post a comment.


Note: HTML is allowed. Your email address will never be published.

Subscribe to comments