Clean ConfigMgr Client Cache - PandaM0nium/MEMC GitHub Wiki
Clean ConfigMgr Client Cache
Method 1 - Create and Deploy Package to collection
Create a Package with the following powershell command to clean client cache
PowerShell.exe -ExecutionPolicy Bypass -File <Script UNC location>\Clean-CMClientCache.ps1
Set package running as normal and run whether the user log in or not
Method 2 - Run Script against collection(s)
Use Script feature in ConfigMgr to clean client cache
Create script in ConfigMgr console and import Clean-CMClientCacheForce.ps1 from UNC
Ensure only the Force script is used for Script deployment as regular version's parameters are not compatible with run script feature
Approve the script
Deploy the script against a collection
Method 3 - Create CI/CB and deploy against collection(s)
ConfigMgr CI/CB can be used to clean up client cache
Approach
Discovery script:
Find out the maximum cache size for Config Manager Client cache by using
$maxCacheSize = (Get-WmiObject -Namespace ROOT\CCM\SoftMgmtAgent -Class CacheConfig).Size
Find out the current C:\Windows\ccmcache folder by using
$currentCacheSize = ((Get-ChildItem C:\Windows\ccmcache -Recurse | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum)/1M
Divide the $currentCacheSize by $maxCacheSize, if the result is more than 0.75 (75%) return $true
Create Configuration Item with above discovery content in discovery script
use Clean-CMClientCache.ps1 as a remediation script
Omit 'Host' in -LoggingOption parameter to suppress any console output
Create Configuration Baseline with above Configuration item
Deploy the Configuration baseline to the collections - make sure to mark Remediate noncompliance rule when supported and set schedule for every month
Creating ConfigMgr client cache report
Add CacheConfig hardware inventory class by adding it in client setting --> Hardware Inventory --> Add --> root\ccm\softmgmtagent and add CacheConfig class
use the following SQL query to construct a report
SELECT
v_GS_LOGICAL_DISK.SystemName0 AS Name,
v_GS_LOGICAL_DISK.Name0 as Drive,
v_GS_LOGICAL_DISK.Size0 AS DiskSizeMB,
v_GS_LOGICAL_DISK.FreeSpace0 AS DiskFreeSpaceMB,
v_GS_CACHECONFIG.Size0 AS SCCMCacheSizeMB,
ROUND(1.0 * v_GS_CACHECONFIG.Size0 / v_GS_LOGICAL_DISK.Size0 * 100, 0) AS PercentOfDisk, v_GS_CACHECONFIG.Location0
AS SCCMCacheLocation,
v_GS_OPERATING_SYSTEM.Caption0
FROM v_GS_LOGICAL_DISK
INNER JOIN
v_GS_OPERATING_SYSTEM ON v_GS_LOGICAL_DISK.ResourceID = v_GS_OPERATING_SYSTEM.ResourceID RIGHT OUTER JOIN
v_GS_CACHECONFIG ON v_GS_LOGICAL_DISK.ResourceID = v_GS_CACHECONFIG.ResourceID
WHERE
(v_GS_LOGICAL_DISK.DriveType0 = 3) AND (LEFT(v_GS_CACHECONFIG.Location0, 2) = v_GS_LOGICAL_DISK.DeviceID0)