Freigeben über


Clear SharePoint Config Cache with PowerShell

Add-PSSnapin -Name Microsoft.SharePoint.PowerShell –erroraction SilentlyContinue
write-host "CLEAR CONFIG CACHE ON FARM" -fore green
$servers = get-spserver | ?{$_.role -eq "Application"}
foreach ($server in $servers)
{
$servername = $server.Address
write-host "Stop Timer Service on server $servername" -fore yellow
(Get-WmiObject Win32_Service -filter "name='SPTimerV4'" -ComputerName $servername).stopservice() | Out-Null
}

foreach ($server in $servers)
{
$servername = $server.Address
$folders = Get-ChildItem ("\\" + $servername + "\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
}

}
}

write-host "Found CacheFolder on Server $servername = $cachefolder" -fore Yellow
$cachefolderitems = Get-ChildItem $cachefolder -Recurse

write-host "Delete all XMQL Files inside this CacheFolder" -fore Yellow
foreach ($cachefolderitem in $cachefolderitems)
{
if ($cachefolderitem -like “*.xml”)
{

$cachefolderitem.Delete()
}

}

$a = Get-Content $cachefolder\cache.ini
$a = 1
write-host "Creating a new Cache.ini File on server $servername" -fore Yellow
Set-Content $a -Path $cachefolder\cache.ini

}

foreach ($server in $servers)
{
$servername = $server.Address
write-host "START Timer Service on server $servername" -fore yellow
(Get-WmiObject Win32_Service -filter "name='SPTimerV4'" -ComputerName $servername).startservice() | Out-Null
}

Comments

  • Anonymous
    January 01, 2003
    thanks i really needed this script

  • Anonymous
    January 01, 2003
    thanks i really needed this script

  • Anonymous
    January 01, 2003
    Thank you for this code, it's super useful. There's no need to load the SharePoint snapin, there's no SharePoint cmdlets used in the script. Thanks!

    • Anonymous
      March 06, 2018
      Get-spserver is the SharePoint cmdlet
  • Anonymous
    December 02, 2013
    Thank you so much! This helped me out when trying to clear the Cache.ini file in a Windows Server 2008 R2 running Microsoft Sharepoint 2013

  • Anonymous
    April 09, 2014
    Hey Thanks Mate, this script really help me out.
    Could some one explain why this issue occurs

  • Anonymous
    August 27, 2014
    The comment has been removed

  • Anonymous
    May 15, 2015
    Hi Thomas, Your solution perfectly worked for me.I was facing this issue in my staging environment and after several IISReset and sp timer service restarts my wsp did not add into the solution store.I took your code and ran , and it worked like a charm. Thanks very much for your code.

  • Anonymous
    October 30, 2015
    Is there a script version for WSS 3.0 ???

  • Anonymous
    January 06, 2016
    Thanks Nice to using it..