By using this site, you agree to the Privacy Policy.
Accept
EnterinITEnterinITEnterinIT
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Reading: Configuration Manager Client Cache Cleanup Script
Font ResizerAa
EnterinITEnterinIT
Font ResizerAa
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
  • WINDOWS
  • SCCM Query Collection List
Search
  • HOME
  • IT PRO
  • TECH
  • MICROSOFT
    • Azure
    • ConfigMgr/SCCM
    • DPM
    • Orchestrator
    • Hyper-V
    • Microsoft Edge Insider
    • MSI
    • Office 365
    • Office Insider
    • Power BI
    • Skype
    • SQL Server
    • Teams
  • WINDOWS
    • Windows Admin Center
    • Windows Client
    • Windows Server
  • SCCM Query Collection List
Configuration Manager Query Collection List
ConfigMgr

Configuration Manager Client Cache Cleanup Script

Published: February 4, 2024
2 Min Read
SHARE

Configuration Manager Client Cache Cleanup Script – Free up Disk Space Easily. You are probably already aware that SCCM manages its client cache pretty well (deletes older objects when free space ends).

This script purges all content in the ccmcache folder that is older than X days. Work with any SCCM release. Below is the code for the compliance rule.

#discover
$MinDays = 20
$UIResourceMgr = New-Object -com “UIResource.UIResourceMgr”
$Cache = $UIResourceMgr.GetCacheInfo()
($Cache.GetCacheElements() |
where-object {[datetime]$_.LastReferenceTime -lt (get-date).adddays(-$mindays)} |
Measure-object).Count
#remediate
$MinDays = 20
$UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
$Cache = $UIResourceMgr.GetCacheInfo()
$Cache.GetCacheElements() |
where-object {[datetime]$_.LastReferenceTime -lt (get-date).adddays(-$mindays)} |
foreach {
$Cache.DeleteCacheElement($_.CacheElementID)
}

NOTE: You may get an error in the report if you don’t set the PowerShell execution policy “Bypass” in Default Client Settings\Computer Agent in SCCM Console.

NOTE: Script only clears cache in the client list. If you upgrade or reinstall SCCM client on the client pc you see that not all folders in c:\windows\ccmcache persist in the cache list. In this situation, you need another script to clear the folder.

To get the list of ccmcache objects run the ps script:

$CMObject = New-Object -ComObject “UIResource.UIResourceMgr”
$CMCacheObjects = $CMObject.GetCacheInfo()
$CMCacheObjects.GetCacheElements()
TAGGED:PowerShellSystem CenterSystem Center Configuration ManagerTechnical PreviewWindowsWindows 10
Previous Article Install WordPress With Nginx on AlmaLinux 9
Next Article Configuration Manager Query Collection List SCCM Current Branch Update 1610
2 Comments 2 Comments
  • Aaron says:
    February 27, 2020 at 11:26 am

    finally a script that works thanks a lot

    Reply
  • Matt R says:
    May 12, 2021 at 5:47 am

    Great Reference! Thanks very much.

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

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

Translation

English中文(简体)DanskNederlandsFrançaisDeutschItaliano한국어PolskiPortuguêsRomânăEspañolУкраїнська
by Transposh - translation plugin for wordpress

Popular Posts

System Requirements for Windows Server 2016
Windows Server
Configuration Manager Query Collection List
Configuration Manager Query Collection List
ConfigMgr
Structured/Managed Navigation enabled on Modern Pages in Classic Team Sites
Tech
SCCM Failed to get DP locations as the expected version from MP
ConfigMgr

Recent Posts

Installing and Configuring Fail2ban for SSH Protection on Ubuntu 24.04
Linux
Enabling and Configuring FirewallD on AlmaLinux
Linux
User Creation and SSH Key Setup in AlmaLinux
Linux
How to reset password on AlmaLinux
Linux

© 2023 EnterinIT

Go to mobile version
Welcome Back!

Sign in to your account

Username or Email Address
Password

Lost your password?