Friday, January 27, 2012

SharePoint - script to clear the timer cache

After reading multiple blogs about standalone clear scripts made to run on one server at a time and parsing through my old batch scripts from the 90s, I put together the following script to quickly iterate through a list of servers in one environment and clear the timer job cache on all hosts.  I have only tested this on SharePoint 2010 SP1/June CU environments. So, test carefully and use at your own risk.  
NOTE:  The server names and GUID of the cache folder will need to be changed to reflect your environment for this script to work. 

REM SharePoint 2010 Timer Service Cache cleanup script
REM Curtis McDonald  
REM 11/22/2011
REM Enter the names of all WFE and APP servers below - SPACE SEPARATED
REM Enter the correct GUID for the farm
set farmservers=(spapp11 spwfe21 spwfe22)
set cachedir=c$\ProgramData\Microsoft\SharePoint\Config\edf927c3-4007-4d5f-b31d-b51fe7a3431a
REM  Stopping timer service on all hosts in farm
FOR %%F IN %farmservers% do sc \%%F stop SPTIMERV4
REM DELETE TIMER JOB CACHE
FOR %%F IN %farmservers% do copy \%%F\%cachedir%\cache.ini \%%F\c$\cache.ini.old
FOR %%F IN %farmservers% do del /Q \%%F\%cachedir%\*.*
FOR %%F IN %farmservers% do echo 1 > \%%F\%cachedir%\cache.ini
REM  Starting timer service on all hosts in farm
FOR %%F IN %farmservers% do sc \%%F start SPTIMERV4
ECHO Waiting for timer job cache rebuild process.
TIMEOUT /T 300

No comments:

Post a Comment