If you’re a SharePoint developer doing On-Premise work, you will often need to restart certain SharePoint services on your SharePoint development machine (and sometimes even on production). Three of the most common services needing frequent restarts during development are:
- The SharePoint Timer Service,
- The SharePoint Administration Service, and
- Internet Information Services (IIS)
When you’re coding your timer jobs and just generally busy doing fun stuff, it can get tedious to keep resetting these services manually. So, I created a cmd (or batch) script that helps you quickly reset the above 3 services. Before each reset, you will be prompted to confirm whether you want to perform the particular reset and if you don’t reply within 10 seconds, the script will automatically proceed with the reset.
Here’s the script:
@echo off @echo SharePoint Script To Restart Services And IIS as posted on https://ehikioya.com/script-to-restart-sharepoint-services-and-iis/ @echo Applies to SharePoint 2010, SharePoint 2013, SharePoint 2016, and SharePoint 2019 @echo Does not apply to SharePoint Online @echo Stopping Sharepoint services... :PROMPT1 REM SharePoint Timer Service CHOICE /C:YN /M "Restart The SharePoint Timer Service?" %1 /T 10 /D Y if %ERRORLEVEL% EQU 2 GOTO PROMPT2 if %ERRORLEVEL% EQU 1 GOTO SUBROUTINE1 :SUBROUTINE1 net stop SPTimerV4 net start SPTimerV4 :PROMPT2 REM SharePoint Administration Service CHOICE /C:YN /M "Restart The SharePoint Administration Service?" %1 /T 10 /D Y if %ERRORLEVEL% EQU 2 GOTO PROMPT3 if %ERRORLEVEL% EQU 1 GOTO SUBROUTINE2 :SUBROUTINE2 net stop SPAdminV4 net start SPAdminV4 :PROMPT3 REM Reset IIS CHOICE /C:YN /M "Reset IIS?" %1 /T 10 /D Y if %ERRORLEVEL% EQU 2 GOTO END if %ERRORLEVEL% EQU 1 GOTO SUBROUTINE3 :SUBROUTINE3 iisreset -restart -noforce :END echo Done. Timer service, admin service, and IIS have been restarted.
This script should work (without modifications) for any On-Premise version of SharePoint server including SharePoint 2010, SharePoint 2013, SharePoint 2016, and SharePoint 2019. It does not apply to SharePoint Online.
Just save the script as a .cmd file and run it. If you like, you can also create a desktop or start menu shortcut to it for a quick and easy way to restart SharePoint services.
If you want an automated way of clearing the SharePoint timer job cache as well, have a look at my article on the subject: Clearing the SharePoint timer job cache using PowerShell