SCCM Configmgr 2012 How to clean software updates files only from client ccmcache folder

 

There are many blog post online ,that discuss about Configuration manager client cache ,how it works, also many questions about content cleanup from ccmcache folder,cache size is increasing beyond the Cachesize limit etc.

when you install Configuration manager client,by default it choose the cache location as %windir%\ccmcache with default size 5GB unless you explicitly specify.you can read the post about Client Cache from my previous blog here.

How to change the configuration manager client cache size using script http://eskonr.com/2013/07/script-to-change-sccm-configmgr-change-client-cache-size/

Recently ,I was monitoring the patch compliance results at my customer and found that ,many of the clients have failed due to low disk space on C drive (default size for ccmcache is 5GB).Yes.what you heard is correct (C drive). Most of the failed Clients are allocated C drive with 40GB (old computers how they setup earlier) .

image

If you read above snippet from TechNet article, software updates also uses client cache but they are not restricted by configured cache size which means,software updates can go beyond 5GB and no restrictions for it.

This issue is fixed in Configuration manager 2012 R2 cumulative update 2 https://support.microsoft.com/en-us/kb/2970177/en-us?wa=wsignin1.0. So make sure you are running min CU2 or above on your Configmgr client to avoid this issue.

So coming to the issue ,Customer is still running on CU1 (no comments pls) and I have to cleanup the ccmcache folder to get some disk space until Configuration manager clients are upgraded to Min CU2 level.

CCMCACHE is also used by applications,packages apart from Software updates .In this case,I choose to cleanup software updates only from CCMCACHE folder.

How to clean software updates files only from client ccmcache folder:

If you want to cleanup the content which is older than 30 days or 60 days irrespective of packages,applications etc, then use the script from here

It took little time for me to identify the difference with applications,packages from software updates.Unlike Configmgr 2007,folders in Configmgr 2012 Client cache are named with single letter and it is difficult to say what is application,package and Software update.

Upon looking at wmi class CacheInfoEx ,namespace Namespace Root\ccm\SoftMgmtAgent ,found what makes the difference with software update file.

for packages and applications,the contentID starts with Content or PackageID and I used logic  in where condition to get all except these (notlike ‘Content*’ and packageID length not ‘8’ ).

Below is the script which deletes software update folders from ccmcache folder ,it also pipes the information about what folders being deleted with freed space into C:\windows\temp\cacheremoval.log

You can polish the script to make it better way .

You can deploy this script via Configmgr 2012 by creating legacy package,program and deploy to collection.

#Title:Delete Software update folders from ccmcache folder on Configmgr 2012 Client
#Author:Eswar Koneti
#dated:06-June-2015
#blog: www.eskonr.com

$CMObject = new-object -com "UIResource.UIResourceMgr"
$cacheInfo = $CMObject.GetCacheInfo()
$objects = $cacheinfo.GetCacheElements()  |
where-object {$_.ContentId.Length -ne 8 -and  $_.ContentId -notlike 'conten*'} |
select-object location, CacheElementID, ContentSize

if ($objects.count -gt 1)
{
$objects |Format-Table -Wrap -AutoSize| tee-object -filepath "C:\windows\temp\cacheremoval.log"

#Now calculate the total space freed
$sum = $objects | Measure-Object -Sum -Property ContentSize
$sum1=[math]::round($sum.sum/1024,2)
"
Freed Space  $sum1 MB" | Out-File "C:\windows\temp\cacheremoval.log" -Append
#delete the software update folders from ccmcache folder

ForEach ($Item in $objects)
{
$cacheInfo.DeleteCacheElement($item.CacheElementID)
}
}

Download the script from TechNet Gallary here

Thanks to my Friend Deepak in helping out the script commands Smile.

11 Responses to "SCCM Configmgr 2012 How to clean software updates files only from client ccmcache folder"

    1. have you tried this using the DCM compliance rule ? it works great. try something like this using the script to remove only software update content
      Query for DCM Rule :

      #discover

      $UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
      $Cache = $UIResourceMgr.GetCacheInfo()
      ($Cache.GetCacheElements() |
      where-object {$_.ContentId.Length -ne 8 -and $_.ContentId -notlike 'conten*'} |
      Measure-object).Count

      Remediation Script for Deletion:

      #remediate
      $UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
      $Cache = $UIResourceMgr.GetCacheInfo()
      $Cache.GetCacheElements() |
      where-object {$_.ContentId.Length -ne 8 -and $_.ContentId -notlike 'conten*'} |
      foreach {
      $Cache.DeleteCacheElement($_.CacheElementID)
      }

      Reply
  1. Hi Eswar,

    Great script just tested the same and it works brilliantly. Thanks for your wonderful work.

    Could you let me know how we can find out using script, content that are set to "Persist content in the client cache"

    Thankyou..

    Reply
      1. Hi,

        Thanks for sharing the script, it works well !!

        However unable to get this working as a SCCM package, set-ExecutionPolicy Unrestricted -force has been set on the PC so if I run it manually it works fine but not as a SCCM legacy package program.
        Program has been set to run with admin rights,SCCM program exits with code is 0 but it does not remove any folders from cache.
        have you seen this behavior before,I am facing the same issue with vb script based method too.

        Reply
          1. Happening to SCCM package that I created using your script. SCCM deployment shows success but does not delete any cache folders. Did you get chance to investigate this behavior?

            Reply
            1. Hi Vilas,
              Have you tried with Configuration Item/Baseline method ? it works good for me. I will look at software deployment method .

              Regards,
              Eswar

Leave a Reply