配置管理器客户端缓存清理脚本 – 轻松释放磁盘空间. You are probably already aware that SCCM manages its client cache pretty well (当可用空间结束时删除旧对象).
此脚本清除 ccmcache 文件夹中早于 X 天的所有内容. Work with any SCCM release. 以下是合规规则的代码.
#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)
}
笔记: 您可能会得到一个 error in the report if you don’t set the PowerShell execution policy “Bypass” in Default Client Settings\Computer Agent in SCCM Console.
笔记: 脚本仅清除客户端列表中的缓存. If you upgrade or reinstall SCCM client on the client pc you see that not all folders in c:\windowsccmcache 保留在缓存列表中. 在这种情况下, 您需要另一个脚本来清除文件夹.
要获取 ccmcache 对象列表,请运行 ps 脚本:
$CMObject = New-Object -ComObject “UIResource.UIResourceMgr”
$CMCacheObjects = $CMObject.GetCacheInfo()
$CMCacheObjects.GetCacheElements()
终于有一个可以运行的脚本了,非常感谢
很好的参考! 非常感谢.