Skip to content

Instantly share code, notes, and snippets.

@nchambe
Created July 25, 2020 18:25
Show Gist options
  • Save nchambe/577caf11bdcb9f3bc2c0493f43427246 to your computer and use it in GitHub Desktop.
Save nchambe/577caf11bdcb9f3bc2c0493f43427246 to your computer and use it in GitHub Desktop.
# Load snap-in if not already
if ((Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue) -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}
# Stop timer service and begin cache-clearing
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
}
}
}
$cacheIn = Get-ChildItem $cachefolder -Recurse
foreach ($cachefolderitem in $cacheIn)
{
if ($cachefolderitem -like "*.xml")
{
$cachefolderitem.Delete()
}
}
$a = Get-Content $cachefolder\cache.ini
$a = 1
Set-Content $a -Path $cachefolder\cache.ini
read-host "press ENTER once script has been run on ALL servers on which you wish to clear the cache to restart the timer service"
start-Service SPTimerV4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment