SCCM 2012 R2 Clear Client Cache (C:\Windows\ccmcache) with command line RRS feed

  • Question

  • Hi,
    is there any command line Parameter, script, ... to clear the SCCM 2012 R2 Client Cache (C:\Windows\ccmcache)?
    Like you do by GUI (Control Panel -> Configuration Manager -> Cache -> Configure Settings -> Delete Files...)
    We would like to clear the cache on our clients silently (Command line, Powershell Script, ...)

    Thank you + Regards

    Monday, March 2, 2015 12:27 PM


All replies

  • Download Roger's Client Center and clear the cache. It will display the Powershell command being used. Or just use the search function. There are numerous scripts available, e.g. 

    Torsten Meringer |

    Monday, March 2, 2015 12:35 PM
  • Thank you, this one did the job

    #Connect to Resource Manager COM Object





    #Enum Cache elements, compare date, and delete older than 60 days


    .GetCacheElements()  |



    found on:

    Wednesday, March 4, 2015 12:40 PM
  • A slight correction. There should be a space after new-object for this script to work. Also, it doesn't look like it deletes items older than 60 days, but rather all cached content.

    $resman = new-object -com "UIResource.UIResourceMgr"
    $cacheInfo = $resman.GetCacheInfo()

    #Enum Cache elements, compare date, and delete them
    $cacheinfo.GetCacheElements()  | foreach {$cacheInfo.DeleteCacheElement($_.CacheElementID)}

    Gary Knigge

    Wednesday, September 28, 2016 8:53 PM
  • Sorry, but why don't you just quote the correct content of the script? You missed half of it..

    #Connect to Resource Manager COM Object
    $resman = new-object -com "UIResource.UIResourceMgr"
    $cacheInfo = $resman.GetCacheInfo()

    #Enum Cache elements, compare date, and delete older than 5 days
    $cacheinfo.GetCacheElements()  |
    where-object {$_.LastReferenceTime -lt (get-date).AddDays(-5)} |
    foreach {$cacheInfo.DeleteCacheElement($_.CacheElementID)

    Thursday, August 10, 2017 9:43 AM
  • Should this be implemented on the clients ? I try running this as admin but for the denied error.

    PS C:\Users\Administrator> #Connect to Resource Manager COM Object
    $resman = new-object -com "UIResource.UIResourceMgr"
    $cacheInfo = $resman.GetCacheInfo()

    #Enum Cache elements, compare date, and delete older than 30 days
    $cacheinfo.GetCacheElements()  | 
    where-object {$_.LastReferenceTime -lt (get-date).AddDays(-30)} | 
    foreach {$cacheInfo.DeleteCacheElement($_.CacheElementID)}
    Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
    At line:6 char:1
    + $cacheinfo.GetCacheElements()  |
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : OperationStopped: (:) [], UnauthorizedAccessException
        + FullyQualifiedErrorId : System.UnauthorizedAccessException

    Thursday, March 22, 2018 4:05 AM
  • Did you run it from an elevated PS? I just tested it and it works perfectly. 

    Garth Jones

    Blog: Old Blog:

    Twitter: @GarthMJ Book: System Center Configuration Manager Reporting Unleased

    Thursday, March 22, 2018 12:09 PM
  • Here's an example for deleting client cache older than 7 days. This will fit inside a ConfigMgr program command line, and can be deployed with the Run program from distribution point option.

    powershell.exe -executionpolicy bypass -windowstyle hidden -command "$x=(New-Object -Com UIResource.UIResourceMgr).GetCacheInfo();$x.GetCacheElements()|?{$_.LastReferenceTime-lt(Get-Date).AddDays(-7)}|%{$x.DeleteCacheElement($_.CacheElementID)}"

    Tuesday, October 23, 2018 6:01 PM
  • This was very useful.  Thank you!
    Thursday, March 28, 2019 7:00 PM
  • Nothing ever seems to delete persistant cache.  How do you get rid of the persistant cache the samea s going into the control panel and delete the cache and ticking off persistant.
    Thursday, December 19, 2019 1:35 PM