ConfigMgr Run Script – Clear CM cache and BranchCache cache

We recently ran into some hash issues with content coming from BranchCache and wanted to clear out the cache on systems to wipe things clean so I did this quick script. I set the BranchCache part inside a comment block and used a # to comment out the comment block. This makes it so I could easily enable or disable the removal of the BranchCache part.

<#
.SYNOPSIS
ConfigMgr Run Script to clear CMCache and BrnachCache

.SYNTAX
clearcache.ps1

.PARAMETER <Parameter_Name>

.INPUTS

.OUTPUTS

.NOTES
FileName: clearcache.ps1
Author: Michael Schultz
Contact:
Created: 20190227
Modified:
Version: 1

.EXAMPLE
clearcache.ps1

#>

#-----Parameters-----

Param (


)
#-----Initializations and Module Imports-----

#-----Variables-----

#-----Functions-----

#-----Logging-----

#-----Execution-----

#clear CM Cache
$UIResourceMgr = New-Object -ComObject UIResource.UIResourceMgr
$Cache = $UIResourceMgr.GetCacheInfo()
#Enum Cache elements, compare date, and delete them
$Cache.GetCacheElements() | foreach {$Cache.DeleteCacheElement($_.CacheElementID)}

#clear BranchCache - Remove first '#' below to turn of BrnachCache flush. Add back to turn back on
#<#
If([System.Environment]::OSversion.Version.Major -ge '10')
{
Clear-BCCache -force
}
else
{
netsh branchcache flush
}
#>

Script on GitHub at https://github.com/NecroMonkey/vault/blob/master/ConfigMgr-Run-Scripts/clearcache.ps1

One thought on “ConfigMgr Run Script – Clear CM cache and BranchCache cache”

  1. Hi. Thanks for this. We recently also started getting hash issues. Been using it for three months. Do you know of any issues causing the need for a script like this?

Comments are closed.