kwizcom banner advertisement

How to Clear SharePoint Configuration Cache using PowerShell?

Clearing 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 my another article: How to Clear SharePoint configuration Cache and this one is PowerShell version of clearing SharePoint 2007/2010/2010 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: http://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 of 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
    }
} 
Credits: https://github.com/chrisdee/Scripts/blob/master/PowerShell/Working/SharePoint/SharePoint2013/SP2013ResetFarmConfigCache.ps1
How to Clear SharePoint Configuration Cache using PowerShell? How to Clear SharePoint Configuration Cache using PowerShell? Reviewed by Salaudeen Rajack on 10:33 AM Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.