Clearing a Client Cache and PowerShell
Recently we had a bad package deployment that was precached. Now we need to delete the bad file while excluding Office 2007 and Office 2003 files if they are present:
1) Delete everything script from Tim Minter on error resume next
dim oUIResManager
dim oCache
dim oCacheElement
dim oCacheElements
set oUIResManager = createobject("UIResource.UIResourceMgr")
if oUIResManager is nothing then
wscript.echo "Couldn't create Resource Manager - quitting"
wscript.quit
end if
set oCache=oUIResManager.GetCacheInfo()
if oCache is nothing then
set oUIResManager=nothing
wscript.echo "Couldn't get cache info - quitting"
wscript.quit
end if
set oCacheElements=oCache.GetCacheElements
for each oCacheElement in oCacheElements
oCache.DeleteCacheElement(oCacheElement.CacheElementID)
next
set oCacheElements=nothing
set oUIResManager=nothing
set oCache=nothing
2) Delete a specific object
a. This would require a modification of the script above to delete the correct package ID.
b. Add input of package ID to exclude. Add test in the for each section to exclude that packageid that matched the ContentID
For fun here is how you would list the cache in powershell
((New-Object -comobject UIResource.UIResourceMgr).getcacheInfo()).GetCacheElements()
A background on the automation of the client cache : http://support.microsoft.com/kb/839513
Translation:
When a package is downloaded to the advanced client cache the client agent places a lock on the package and the lock is not removed until a day later (24 hours) after the program is executed or a month (30 Days) if the package has not be executed. When the lock is removed from the package a day or a month later depending in the circumstance it cannot be re-locked until it is removed from the client cache and downloaded again.
When your packages need to be downloaded locally to the advanced client and the cache is full or lacks sufficient free space to accommodate the download the client will enumerate the packages in the cache if any exist and attempt to determine if the existing packages in the cache have already executed and the allotted 24 hours has not yet passed. If it finds packages where this is the case the agent then deletes them to allow more free space and then attempts to download the package again. On the second attempt to download the package if there is now sufficient free space remaining the package is downloaded to be executed.
SCCM: http://technet.microsoft.com/en-us/library/bb892803.aspx