Clearing the SharePoint configuration cache using PowerShell

Here is a simple function that will automatically detect your SharePoint configuration, disable the SharePoint Timer service, clear the configuration cache, and restart the SharePoint Timer service.

Function Clear-SPConfigCache{
$ConfigDB = Get-SPFarm
$Config = Get-SPDatabase | Where{$_.Name -eq $}

Write-Host "Configuration database Id: " $Config.Id.Guid -foregroundcolor Green

$ConfigPath = "C:\ProgramData\Microsoft\SharePoint\Config\"
$ConfigCache =$ConfigPath+$Config.Id.Guid

Write-Host "Disabling and stopping SharePoint Timer Service" -foregroundcolor Yellow
Set-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\SPTimerV4 -name Start -value 4
Stop-Service -displayname "SharePoint Timer Service"

Write-Host "Deleting SharePoint configuration cache files" -foregroundcolor Red
Remove-Item $ConfigCache\* -Force
New-Item -Path $ConfigCache -Name cache.ini -ItemType "File" -Value "1"

Write-Host "Enabling and starting SharePoint Timer Service" -foregroundcolor Green
Set-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\SPTimerV4 -name Start -value 2
Start-Service -displayname "SharePoint Timer Service"

Note: The SharePoint Timer service is SPTimerV4.  This may change in the next version of the software.

Comments (0)

Skip to main content