Download SCCM Client Cache Clean Up Script

4
SCCM Cache Clean Up Script

Do you have problems with SCCM Client cache? In this post, you can learn and download an SCCM Cache Clean Up Script. I will explain how to delete the specific package from SCCM Cache by providing the PackageID /Content ID and also Delete folder which exceeds particular size.

These are two scripts for which can be used for different purpose. First one is to delete the folder with Specific Package ID /Content ID and the second one is to delete the folder which is beyond a specific size. The full script has been provided in the below link.

SCCM Cache Clean UP with Specific Package ID or Content ID

Recently I came across a specific requirement to remove the content from SCCM Cache based on the Package id. Delete the SCCM cache folder with the script. You have to provide the package ID or content ID of the folder which you want to delete.

CAS.log – The Content Access service. Maintains the local package cache on the client.

We can see the package/content information from the CAS.log along with folder name which holds the packages and application files.

cac

$string=Read-CMLogfile -path $caslogpath

Read the Cas.log and look for the content id where the same log line has the location of the package folder.

$lookforcontent1=” — Cache content id:$contentId”+”*”

$ccmsetup_val= $string.LogText -match $lookforcontent1

$LocationPath=$ccmsetup_val.split()[-1]

$deleteFolder= $LocationPath.substring(9)

Full Script Link

Script3

From CAS.log

Screenshot with content id as input.

SCCM Cache Clean Up Script

screenshot with PackageID as input.

SCCM Cache Clean Up Script

SCCM Cache Clean Up Script – Folders Larger than a Specific Size

This SCCM Cache Clean Up script will remove any folder which is larger than the size of 12 MB.

[int]$sizeMb = “{0:N2}” -f ($subFolderItems.sum / 1MB)

if ($sizeMb -ge $sizeMax) {

Get-ChildItem $i.FullName | Remove-Item -Force -Recurse -Verbose }

Download SCCM Cache Clean Up Script

The SCCM client cache on Windows computers stores temporary files used to install applications and programs.If the client attempts to download a package that is less than the size of the cache but the cache is full, all required deployments keep retrying until the cache space is available, the download times out, or the retry count reaches its limit.The client generates status message 10050 for insufficient cache sizeThe client tries to download the content every four hours until it has tried 18 times.

Cached content is not automatically deleted but remains in the cache for at least one day after the client used that content. If you configure the package properties with the option to persist content in the client cache, the client does not automatically delete the package content from the cache. If the cache space is used by packages downloaded within the last 24 hours and the client must download new packages, you can either increase the cache size or choose the option to delete persisted cache content.
This script will delete the CCM folder which is beyond specific size

Download Full Script

https://gallery.technet.microsoft.com/CCMCache-delete-folder-eb03ba26

4 COMMENTS

  1. In my opinion it is better to peform the clean-up using the CM client
    Example to clean all

    #Delete all elements in Configuration Manager client cache

    $CMObject = New-Object -ComObject “UIResource.UIResourceMgr”
    $CMCacheObjects = $CMObject.GetCacheInfo()
    $CMCacheElements = $CMCacheObjects.GetCacheElements()

    Foreach ($CacheElement in $CMCacheElements)

    {
    $CMCacheObjects.DeleteCacheElementEx($CacheElement.CacheElementID)
    }

    • Exactly, furthermore each cache element has a contentsize property. To steal from the example above, you could filter on that property:

      $sizeMB = 30

      $CMObject = New-Object -com “UIResource.UIResourceMgr”
      $cacheInfo = $CMObject.GetCacheInfo()
      $objects = $cacheinfo.GetCacheElements()

      $objects | Where-Object {$_.ContentSize/1024 -gt $sizeMB} | ForEach-Object {
      $cacheInfo.DeleteCacheElement($_.CacheElementId)
      }

  2. Also, to remove by ContentID:

    $contentId=’2a77afe3-1e82-48da-b817-2f69e2c8218c’

    $cacheFile = Get-CimInstance -Namespace root\ccm\SoftMgmtAgent -ClassName cacheinfoex -Filter “ContentId = ‘$ContentID'”

    $CMObject = New-Object -com “UIResource.UIResourceMgr”
    $cacheInfo = $CMObject.GetCacheInfo()
    $objects = $cacheinfo.GetCacheElements()

    $objects | Where-Object { $PSItem.CacheElementID -match $cacheFile.CacheId } | ForEach-Object {
    $cacheInfo.DeleteCacheElement($PSItem.CacheElementId)
    }

    • I really appreciate your comments/suggestion

      Basic idea is to create script from the log and these logs has many vital information Also I didn’t find any related blog for string parsing with same activity so thought of writing one. I believe this is good start to parse the logs for future Automation.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.