Here is an example PowerShell script to demonstrate how to properly remove items (Packages, Software Updates, etc) from the ConfigMgr Client Cache that have not been referenced in the past 60 days:
1: #Connect to Resource Manager COM Object
2: $resman = new-object -com "UIResource.UIResourceMgr"
3: $cacheInfo = $resman.GetCacheInfo()
4: #Enum Cache elements, compare date, and delete older than 60 days
5: $cacheinfo.GetCacheElements() |
6: where-object {$_.LastReferenceTime -lt (get-date).AddDays(-60)} |
7: foreach {$cacheInfo.DeleteCacheElement($_.CacheElementID)}
8:
The following is an example VBScript to delete all items in the local cache:
1: on error resume next
2: dim oUIResManager
3: dim oCache
4: dim oCacheElement
5: dim oCacheElements
6: set oUIResManager = createobject("UIResource.UIResourceMgr")
7: if oUIResManager is nothing then
8: wscript.echo "Couldn't create Resource Manager - quitting"
9: wscript.quit
10: end if
11: set oCache=oUIResManager.GetCacheInfo()
12: if oCache is nothing then
13: set oUIResManager=nothing
14: wscript.echo "Couldn't get cache info - quitting"
15: wscript.quit
16: end if
17: set oCacheElements=oCache.GetCacheElements
18: for each oCacheElement in oCacheElements
19: oCache.DeleteCacheElement(oCacheElement.CacheElementID)
20: next
21: set oCacheElements=nothing
22: set oUIResManager=nothing
23: set oCache=nothing
Either of these scripts can be distributed using normal ConfigMgr software distribution – You must have PowerShell installed on the client to successfully execute the PowerShell script.
Review more information about the CacheElement Class for ConfigMgr 2007.
ConfigMgr MVP | DellTechCenter | @ramseyg | greg_ramsey@dell.com
View the full article

Sign In
Register
Help

MultiQuote