Tuesday, May 14, 2013

Clear SharePoint Config Cache with PowerShell


Add-PSSnapin -Name Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue

Stop-Service SPTimerV4
$folders = Get-ChildItem C:\ProgramData\Microsoft\SharePoint\Config
foreach ($folder in $folders)
    {
    $items = Get-ChildItem $folder.FullName -Recurse
    foreach ($item in $items)
        {
            if ($item.Name.ToLower() -eq "cache.ini")
                {
                    $cachefolder = $folder.FullName
                }
               
        }
    }
$cachefolderitems = Get-ChildItem $cachefolder -Recurse
    foreach ($cachefolderitem in $cachefolderitems)
        {
            if ($cachefolderitem -like "*.xml")
                {
                   $cachefolderitem.Delete()
                }
       
        }
       
$a = Get-Content  $cachefolder\cache.ini
$a  = 1
Set-Content $a -Path $cachefolder\cache.ini

read-host "Do this on all your SharePoint Servers - and THEN press ENTER"
start-Service SPTimerV4

4 comments:

  1. Thanks Thomas for posting this info !!

    ReplyDelete
  2. SharePoint 2003 was the first version of this series. But latest version is Microsoft SharePoint Server 2013 Final Free download with fresh and updated links.

    ReplyDelete
  3. Do you know why this message would come up after copying and pasting your script?

    At C:\SharePoint\Scripts\CLEAR_SP_CACHE.ps1:32 char:71
    + read-host "Do this on all your SharePoint Servers and THEN press ENTER"
    + ~
    The string is missing the terminator: ".
    + CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : TerminatorExpectedAtEndOfString

    ReplyDelete