
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.
TL;DR
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.
$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
From CAS.log
Screenshot with content id as input.
screenshot with PackageID as input.
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
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)
}
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.
HI all;
Thanks very much for this valuable information, what about the remediation script?
Script will remove the Cache folder of that package based on the input(Package ID or Content ID) provided
This Post really should be removed. Deleting CCMCache Items from the file system is not supported and leaves orphaned content in WMI. The Client still thinks the Content is on the system, then when it tries to call it, it’s gone, throwing errors. You need to use the methods as described in the comments. Script should also be removed from TechNet.