Workaround script to clean up SCCM 1610 orphaned cache

SCCM 1610 at launch had a bug that caused agent upgrades to forget about cached content. Cached data stays behind until you clean it up manually, not cool for small SSDs. More here https://support.microsoft.com/en-us/kb/3214042

So I wrote a small script to roll out with compliance and remove stale data.

Seems to work but test before use. See comments for PowerShell 2.0 fix.

$CCMCache = (New-Object -ComObject "UIResource.UIResourceMgr").GetCacheInfo().Location
#For some reason it doesn't properly directly select required attribute for returned multi-instance object so I have to loop it. Some strange COM-DotNet interop problem?
$ValidCachedFolders = (New-Object -ComObject "UIResource.UIResourceMgr").GetCacheInfo().GetCacheElements() | ForEach-Object {$_.Location}
$AllCachedFolders = (Get-ChildItem -Path $CCMCache -Directory).FullName

ForEach ($CachedFolder in $AllCachedFolders) {
    If ($ValidCachedFolders -notcontains $CachedFolder) {
        Remove-Item -Path $CachedFolder -Force -Recurse
    }
}

1 thought on “Workaround script to clean up SCCM 1610 orphaned cache”

  1. Ha thank you very much for this i’m not a scripter and was having trouble doing exactly that! Love how in the kb3214042 they just say “any expired content can be manually deleted as needed” like I want to do that on 6000+ workstation… anyway…
    on windows 7 and powershell version 2.0 I had to to change line 4 for
    $AllCachedFolders = (Get-ChildItem -Path $CCMCache) | select fullname -ExpandProperty fullname
    to make it work.
    Thanks again

Leave a Reply

Your email address will not be published. Required fields are marked *