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

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
Answers
-
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)}
- Proposed as answer by Garth JonesMVP, Moderator Wednesday, March 4, 2015 12:53 PM
- Marked as answer by Joyce LModerator Tuesday, March 10, 2015 9:37 AM
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
- Proposed as answer by Richard.Knight Monday, March 2, 2015 1:01 PM
-
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)}
- Proposed as answer by Garth JonesMVP, Moderator Wednesday, March 4, 2015 12:53 PM
- Marked as answer by Joyce LModerator Tuesday, March 10, 2015 9:37 AM
-
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
- Proposed as answer by Christan Möckel Monday, December 3, 2018 9:06 AM
-
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/
-
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
-
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
-
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)}"
-