none
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
    Stefan

    Monday, March 2, 2015 12:27 PM

Answers

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. http://cm12sdk.net/?p=1526 

    Torsten Meringer | http://www.mssccmfaq.de

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

    #Connect to Resource Manager COM Object


    $resman

    =new-object-com"UIResource.UIResourceMgr"


    $cacheInfo

    =$resman.GetCacheInfo()


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


    $cacheinfo

    .GetCacheElements()  |


    foreach

    {$cacheInfo.DeleteCacheElement($_.CacheElementID)}

    found on: http://myitforum.com/cs2/blogs/gramsey/archive/2010/07/23/how-to-properly-remove-items-from-configmgr-client-cache.aspx

    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)

    http://myitforum.com/myitforumwp/2011/11/10/how-to-properly-remove-items-from-configmgr-client-cache-using-powershell-and-vbscript/

    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: http://www.enhansoft.com/blog Old Blog: http://smsug.ca/blogs/garth_jones/default.aspx

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

    Thursday, March 22, 2018 12:09 PM
    Moderator
  • 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