Useful SharePoint script to restart SharePoint services and IIS

A SharePoint developer’s life is filled with many things, but one of the most common is the old faithful iisreset, coupled with a reset of the Timer Service and the Admin Service. When you’re working on timer jobs, it can get tedious quickly to have to ┬ákeep resetting things.

So I’m sharing a useful batch script I knocked together to do it for you. It will perform three functions – restart the SharePoint 2010 Timer Service, the SharePoint 2010 Administration Service and do an IISReset. It will prompt you if you want to do each of them, and if you don’t reply within 5 seconds automatically do it.

Simply save it as a .cmd file, and then create a shortcut to it, and put that shortcut on your start menu/quick launch. Restarts ahoy!

Enjoy.

@echo off
@echo Quick SharePoint services restart - from www.thorntontechnical.com
@echo Stopping Sharepoint services...

:P1
REM - SharePoint timer service
CHOICE /C:YN /M "Restart Timer Service?" %1 /T 5 /D Y

if ERRORLEVEL ==2 GOTO P2
if ERRORLEVEL ==1 GOTO A1
:A1
net stop "sharepoint 2010 timer"
net start "sharepoint 2010 timer"
:P2
REM - SharePoint timer service
CHOICE /C:YN /M "Restart Admin Service?" %1 /T 5 /D Y
if ERRORLEVEL ==2 GOTO P3
if ERRORLEVEL ==1 GOTO A2
:A2
net stop "sharepoint 2010 administration"
net start "sharepoint 2010 administration"
:P3
REM - reset IIS
CHOICE /C:YN /M "Reset IIS?" %1 /T 5 /D Y
if ERRORLEVEL ==2 GOTO END
if ERRORLEVEL ==1 GOTO A3
:A3
iisreset -restart -noforce
:END
echo Finished. Thanks. Have fun.


Tags: , , , , , ,

2 Responses to “Useful SharePoint script to restart SharePoint services and IIS”

  1. Gurdeep says:

    Hi,

    What would be the typical reason to use a script that resets those services?

  2. Typically whenever you’re doing anything with custom assemblies, and especially the timer service. i.e., if you deploy a new timer job you need sometimes need to reset IIS and the timer service to ensure it’s running the latest version of the code.

Leave a Reply