Skip to main content

Wouter

Go Search
Home
Contact Me
  

Wouter > Posts > Reset the SharePoint config cache using PowerShell
Reset the SharePoint config cache using PowerShell

In very, very, broad and general terms, there are two types of databases in SharePoint. The configuration database stores configuration data and you have content databases to store the content in the farm. The configuration database houses XML serialized objects. These objects are also cached on disc on each server in the farm. Sometimes, this cache can get out of sync and you have to reset the cache. This involves stopping the timer service, clearing out a special folder, and resetting a cache management file.

You can download this demo from my CodePlex site at http://woutersdemos.codeplex.com/releases/view/85474.

The following script automates this on all machines in the server farm by using PowerShell and the SharePoint object model to figure out which servers take part in the farm. If you do decide to run it, the following will be displayed.

The content of the generic script is as follows. Note that the entire script is generic and works on any SharePoint farm. PowerShell remoting should be configured to work correctly on your farm, which I hope is already the case J

First, get all server names of the valid servers in the SharePoint farm.

$Servers = Get-SPServer | ? {$_.Role -ne "Invalid"} |
  Select -ExpandProperty Address
Write-Host "This script will reset ...."
$Servers | Foreach-Object { Write-Host $_ }
Write-Host "Press enter to start."
Read-Host

Next, use PowerShell remoting to run a script block on each server. Use try / finally to ensure that the timer service will always be started again no matter what.

Invoke-Command -ComputerName $Servers -ScriptBlock {
  try { 

First, stop the timer service which has locks on the configuration cache.

    Write-Host "$env:COMPUTERNAME - Stopping timer service"
    Stop-Service SPTimerV4 

Retrieve the ID of the configuration database from the registry. This ID identifies the caching folder on disc.

    $ConfigDbId = [Guid](Get-ItemProperty '<registry key>' -Name Id).Id
    $CacheFolder = Join-Path -Path ([Environment]::GetFolderPath(
      "CommonApplicationData")) 
      -ChildPath "Microsoft\SharePoint\Config\$ConfigDbId"
    Write-Host "$env:COMPUTERNAME - Clearing cache folder $CacheFolder"

Clear out the cache.

    Get-ChildItem "$CacheFolder\*" -Filter *.xml | Remove-Item

Locate the cache ini file and reset it by writing the value '1' into the file.

    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
  }
}

Presto! One generic script that you can call as an admin or make use of in an installation procedure.

Hope it helps!

Comments

There are no comments yet for this post.
Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Name (required) *


Your Url

Type the Web address: (Click here to test)  

Type the description: 

Comments (required) *

Attachments