How to Clear SharePoint Configuration Cache using PowerShell?

Clearing the SharePoint configuration cache would be the solution for many common issues such as “An update conflict has occurred, and you must re-try this action”. Manually clearing the SharePoint 2007 configuration cache is explained in another article: How to Clear SharePoint Configuration cache? And this one is the PowerShell version of clearing SharePoint 2007/2010/2013 configuration cache.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

#Stop SharePoint 2013 Timer service
Stop-Service SPTimerV4

#Configuration Cache folder
$folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config 

#Get the GUID folder where cache.ini lives.
foreach ($folder in $folders)
    {
    $items = Get-ChildItem $folder.FullName -Recurse
    foreach ($item in $items)
        {
            if ($item.Name.ToLower() -eq "cache.ini")
                {
                    $cachefolder = $folder.FullName
                }                
        }
    }
#Delete all XML Files
$cachefolderitems = Get-ChildItem $cachefolder -Recurse
    foreach ($cachefolderitem in $cachefolderitems)
        {
            if ($cachefolderitem -like "*.xml")
                {
                   $cachefolderitem.Delete()
                }        
        }
#Set "Cache.ini" file's content to 1        
$a = Get-Content  $cachefolder\cache.ini
$a  = 1
Set-Content $a -Path $cachefolder\cache.ini

#Start SharePoint Timer Service
start-Service SPTimerV4 

Credits to: https://blogs.technet.com/b/sp/archive/2013/05/29/clear-sharepoint-config-cache-with-powershell.aspx

Reset SharePoint 2013 Configuration Cache on all servers:

This one does it on all the servers in SharePoint farm:

Add-PSSnapin microsoft.sharepoint.powershell -ea SilentlyContinue

#Get all SharePoint Servers
$Servers = Get-SPServer | ? {$_.Role -ne "Invalid"} | Select -ExpandProperty Address

#Iterate through each server and reset SharePoint config cache
Invoke-Command -ComputerName $Servers -ScriptBlock {
try {
        Write-Host "$env:COMPUTERNAME - Stopping timer service"
        Stop-Service SPTimerV4

        #Get Config Cache Folder
        $ConfigDbId = [Guid](Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\15.0\Secure\ConfigDB' -Name Id).Id #Path to the '15 hive' ConfigDB in the registry
        $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath("CommonApplicationData")) -ChildPath "Microsoft\SharePoint\Config\$ConfigDbId"

        Write-Host "$env:COMPUTERNAME - Clearing cache folder $CacheFolder"
        #Delete all XML Files
        Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item

        Write-Host "$env:COMPUTERNAME - Resetting cache ini file"
        $CacheIni = Get-Item "$CacheFolder\Cache.ini"
        Set-Content -Path $CacheIni -Value "1"
    }
finally{
        Write-Host "$env:COMPUTERNAME - Starting timer service"
        Start-Service SPTimerV4
    }
}

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

2 thoughts on “How to Clear SharePoint Configuration Cache using PowerShell?

Leave a Reply

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