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 $ConfigDB.name} 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 YellowSet-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\SPTimerV4 -name Start -value 4Stop-Service -displayname "SharePoint Timer Service" Write-Host "Deleting SharePoint configuration cache files" -foregroundcolor RedRemove-Item $ConfigCache\* -ForceNew-Item -Path $ConfigCache -Name cache.ini -ItemType "File" -Value "1" Write-Host "Enabling and starting SharePoint Timer Service" -foregroundcolor GreenSet-Itemproperty -path HKLM:\SYSTEM\CurrentControlSet\Services\SPTimerV4 -name Start -value 2Start-Service -displayname "SharePoint Timer Service"} |
Note: The SharePoint Timer service is SPTimerV4. This may change in the next version of the software.