Configuration Manager Client Cache Cleanup Script – Spazio su disco libera facilmente. You are probably already aware that SCCM manages its client cache pretty well (Elimina gli oggetti più vecchi quando lo spazio libero termina).
Questo script elimina tutti i contenuti nella cartella CCMCACHE che è più vecchia di X giorni. Work with any SCCM release. Di seguito è riportato il codice per la regola di conformità.
#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)
}
NOTA: Potresti ottenere un error in the report if you don’t set the PowerShell execution policy “Bypass” in Default Client Settings\Computer Agent in SCCM Console.
NOTA: Lo script cancella solo la cache nell'elenco client. If you upgrade or reinstall SCCM client on the client pc you see that not all folders in c:\Windows ccmcache persistono nell'elenco cache. In questa situazione, Hai bisogno di un altro script per cancellare la cartella.
Per ottenere l'elenco degli oggetti CCMCACHE Esegui lo script PS:
$CMObject = New-Object -ComObject “UIResource.UIResourceMgr”
$CMCacheObjects = $CMObject.GetCacheInfo()
$CMCacheObjects.GetCacheElements()
Finalmente una sceneggiatura che funziona grazie mille
Ottimo riferimento! Thanks very much.