Clearing SharePoint configuration cache using PowerShell:

Have you come across an error: An update conflict has occurred, and you must re-try this action
I'm sure you did, as there is no way any SharePoint Admin would be spared with this error. 
This errors may come up in the following scenarios:
  • You are performing SharePoint Patching and while running the upgrade command via PowerShell you are presented with this error
  • You are trying to run some PowerShell script and this error pops-up
Clearing SharePoint Configuration Cache will help in the following scenarios:
  • To fix SharePoint Upgrade and Patching issues
  • SharePoint Timer Jobs stuck or running slow
  • Nintex Workflows or any Workflows failing to work intermittently and more..

Clearing SharePoint Configuration Cache is one of the safe things to try while troubleshooting, and sometimes even the most unexpected, unforgiving errors maybe resolved by quickly performing SharePoint Cache Configuration clearing. Thereby this is one of things to try when you are working on a long running issue

The guide to clear the SharePoint Configuration Cache is well documented here –

https://support.microsoft.com/en-us/help/939308/error-message-when-you-try-to-modify-or-to-delete-an-alternate-access

I always hated doing this way, especially if you are working on a Multi-Server SharePoint Farm as there are too many manual steps

Upon researching online to find a suitable PowerShell script, I found this well written script and I have used this script a few hundred times and works perfectly

https://mickeyjervin.wordpress.com/category/powershell/

There are few things you should note though..

Always remember to take backups of the Config folder. I have seen cases where the config cache refuses to rebuild from the SharePoint Configuration Database, and if you have no good backups, then you are in deep sh**

Which folder should we backup: “Drive:\ProgramData\Microsoft\SharePoint\Config\GUID” the GUID folder

Backing this GUID folder in any one of the Servers is good enough, and in worst case scenarios you can use the same backup and put it on every SharePoint Server in the Farm

I customized the above PowerShell so that it can automatically do the Backups for me 
and then clear the SharePoint Configuration Cache

The attached script at the bottom of this article, will work for SharePoint 2013 only

To get this working on a SharePoint 2010 Farm, open the file in Notepad++ , go to Line-24, update:

From:

Set-Variable timerServiceName -option Constant -value “SharePoint Timer Service

To:

Set-Variable timerServiceName -option Constant -value “SharePoint 2010 Timer

Save the file and now the exact same file can be run on SharePoint 2010 Farms

Prepare the Server, Trust me this is worth the Time and a one-time effort

I usually choose Central Admin Server and create the following folders & files:

  1. Choose a Drive on which you want place the backups and the Script. Choose other than Primary C:\Drive. In this I’m choosing D:\Drive
  2. Create a Folder called ‘ConfigCache’
  3. Inside ‘ConfigCache’ folder, create a folder called ‘Backups’, this is config folder backups will be stored
  4. Create a bat file called TimerCacheCode.bat

How to create a bat file? Create a blank notepad file and rename the .txt to .bat

  1. Open the TimerCacheCode.bat in notepad and add the following code:
%~d0

cd “%~dp0”

Powershell.exe .\2013ConfigCache.ps1

Pause

  1. Place the attached 2013ConfigCache.ps1 script inside ‘ConfigCache’ folder
  2. Your folder structure should now look like shown below:

  1. Open the 2013ConfigCache.ps1 script file using Notepad++, update the following lines:
    • Line 207: Update the folder path: D:\ConfigCache\Backups, depending on where which Drive was chosen to create the Folders
    • Line 210: Update the folder path: D:\ConfigCache\Backups, depending on where which Drive was chosen to create the Folders
    • Line 212: In this script, it is assumed that the Config folder is in the default location which is: C:\ProgramData\Microsoft\SharePoint\Config, update accordingly
  1. Once this is ready, whenever you want to clear the SharePoint Configuration Cache, just go to the TimerCacheCode.bat and Run as Administrator

  1. The output will look as follows:

If you have trouble in getting the desired output, let me know in comments section. I'll see what I can do to help you fix this. 

The PowerShell script and the bat file is attached here. Rename the PowerShell script to .ps1 and the bat file to .bat

2013ConfigCache.ps1  TimerCacheCode

Leave a Reply

Your email address will not be published.