How to delete the Sharepoint configuration cache with Powershell

With this script you will be able to delete the configuration cache easily, no need to go to the folder manually and delete the files, and then open the cache.ini file and put a number one one it.

Automation FTW,

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