Technology Toolbox

Your technology Sherpa for the Microsoft platform

Jeremy Jameson - Founder and Principal

Search

Search

Script to Restart SharePoint Services

Note
This post originally appeared on my MSDN blog:

Since I no longer work for Microsoft, I have copied it here in case that blog ever goes away.

Since my previous post introduced one of my SharePoint Toolbox scripts, I thought I should share another one that is more applicable to a broader audience.

As I've noted in the past, memory leaks are certainly not uncommon in the world of SharePoint. Consequently, you may want to periodically simulate a reboot of your development environment in order to free up memory and get back to being productive. Trust me, simulating a reboot is much, much faster than actually rebooting.

To do this, I created the following script and dropped it in my SharePoint Toolbox folder (\NotBackedUp\Public\Toolbox\SharePoint\Scripts\Restart SharePoint Services.cmd):

@echo off

@echo Stopping services...

iisreset /stop /noforce

net stop "Windows SharePoint Services Timer"

net stop "Windows SharePoint Services Administration"

net stop "Office SharePoint Server Search"

net stop "Windows SharePoint Services Search"

net stop "Windows SharePoint Services Tracing"

@pause

@echo Starting services...

net start "Windows SharePoint Services Tracing"

net start "Windows SharePoint Services Search"

net start "Office SharePoint Server Search"

net start "Windows SharePoint Services Administration"

net start "Windows SharePoint Services Timer"

iisreset /start

@pause

Note that I use a pause statement so that I can optionally perform other tasks while SharePoint is stopped (e.g. detach a content database, move it to a different disk, and then reattach it).

Comments

  1. # re: Script to Restart SharePoint Services

    January 21, 2010 7:22 PM
    John Thompson

    Because every environment may have optional components active or not I adjusted your script as follows in my toolkit:

    @echo off

    @echo Stopping services...

    iisreset /stop /noforce

    SET IIS=%errorlevel%

    net stop "Windows SharePoint Services Timer"

    SET TIMER=%errorlevel%

    net stop "Windows SharePoint Services Administration"

    SET ADMIN=%errorlevel%

    net stop "Office SharePoint Server Search"

    SET OSSS=%errorlevel%

    net stop "Windows SharePoint Services Search"

    SET WSSS=%errorlevel%

    net stop "Windows SharePoint Services Tracing"

    SET WSST=%errorlevel%

    @pause

    @echo Starting services...

    IF %WSST%==0 net start "Windows SharePoint Services Tracing"

    IF %WSSS%==0 net start "Windows SharePoint Services Search"

    IF %OSSS%==0 net start "Office SharePoint Server Search"

    IF %ADMIN%==0 net start "Windows SharePoint Services Administration"

    IF %TIMER%==0 net start "Windows SharePoint Services Timer"

    IF %IIS%==0 iisreset /start

    SET IIS=

    SET TIMER=

    SET ADMIN=

    SET OSSS=

    SET WSSS=

    SET WSST=

    @pause

  2. # re: Script to Restart SharePoint Services

    March 10, 2010 4:07 PM
    Jeremy Jameson
    Gravatar

    @John Thompson:

    Good tip, thanks.

    By the way, if you set environment variables like this in a script, I highly recommend adding "setlocal" after the "@echo off" statement at the top of the file. That way you don't need to worry about having the environment variables defined after the script finishes executing.

  3. # Random Musings of Jeremy Jameson Script to Restart SharePoint Services | fix my credit

    June 16, 2009 9:21 AM
    fixmycrediteasily.info

Add Comment

Optional, but recommended (especially if you have a Gravatar). Note that your email address will not appear with your comment.
If URL is specified, it will be included as a link with your name.

To prevent spam from being submitted, please select the following fruit: Grapes

Strawberry
Pear
Watermelon
Grapes
Apple
Cherries
 
Please add 1 and 4 and type the answer here: