Thursday, 8 December 2011

Manage services on SharePoint 2010 servers using PowerShell

As you may already know, you can use the “Manage Services on Server” option from Central Administration to centrally start and stop service instances across all SharePoint servers in your farm. An example of this administration page is shown below:


The issue with this page is that it can be cumbersome to use if there are a few servers in your farm and you keep having to click the “Server” drop-down to select one of them. It is also not very repeatable and there may be issues where you might want to automate the process – for example, stopping the User Profile Synchronization Service before a backup or application update and restarting it once complete.

You can get a similar list to the one shown in Central Admin using PowerShell by typing the following command:

Get-SPServiceInstance -Server PAC-SP2010 | sort TypeName | Format-Table -AutoSize

This will not only provide the service name and status, but also the service instance GUID:


There are a couple of ways to stop a service instance. Firstly, the most user friendly method, which is to use the service display name and then call the Stop-SPServiceInstance cmdlet:

Get-SPServiceInstance -Server PAC-SP2010  | where-object {$_.TypeName -eq "Managed Metadata Web Service" } | Stop-SPServiceInstance -Confirm:$false

There are a couple of things to note here:

  • The -Server switch is not required if you are configuring service instances for the server you are currently logged into
  • The -Confirm:$false switch is also optional. Setting this to $false supresses the confirmation prompt that appears when attempting to stop the service instance through PowerShell
  • You can also use the Stop-SPServiceInstance cmdlet directly by specifying the service instance GUID, as shown below for the Managed Metadata Web Service on this farm:

    Stop-SPServiceInstance -Identity 3f36d0f4-ce39-48aa-a776-6300f1e2b58f -Confirm:$false


    Restarting the service is simply a case of typing either of the same commands as before, but this time replacing Stop-SPServiceInstance with Start-SPServiceInstance.

    First example:

    Get-SPServiceInstance -Server PAC-SP2010  | where-object {$_.TypeName -eq "Managed Metadata Web Service" } | Start-SPServiceInstance -Confirm:$false

    Second example:

    Start-SPServiceInstance -Identity 3f36d0f4-ce39-48aa-a776-6300f1e2b58f -Confirm:$false

    That’s great, but you also might want to check a service instance has a particular status before attempting to stop or start it. In the example below, the Managed Metadata Web Service instance is associated with the $serviceinstance variable and the Status is checked to make sure it is “Online” before attempting to stop the service instance:

    $serviceinstance = Get-SPServiceInstance -Server PAC-SP2010  | where-object {$_.TypeName -eq "Managed Metadata Web Service" }
    if ($serviceinstance.Status -eq "Online")
        Write-Host "Stopping Managed Metadata Web Service on PAC-SP2010"
            $serviceinstance | Stop-SPServiceInstance -Confirm:$false
        catch { Write-Host "There was an error:" $_ }
        Write-Host "Managed Metadata Web Service on PAC-SP2010 has already been stopped"


    1. Very Nice Friends..

      i am From colombia and you Blog very nice.


      Andres Franco

    2. Hi Phil.

      Thanks for this.
      How would i write a script which lists all the service applications on each server.

      I have started it of as
      $ = (get-spfarm).Servers #gets the number of servers in the farm

      But i need to do a for each loop for each SharePoint server (excluding the sql) so it gives loops through each server and displays the Service Applications for each server.
      How can this be acheived?


    3. Maybe something like this:

      (get-spfarm).servers | where {$_.Name -ne "SQL"} | foreach {write-host "====== $_ ======";Get-SPServiceInstance -Server $ | sort status,typename | ft}

    4. This is simply awesome. thanks for sharing this!!

    5. How do I remove the service entirely (not just stop it)?

    6. great information !

    7. Thanks for your valuable posting.I have collect more than information from your website. It is really wonderful blog. please added more than tips. i'm working in Erp in india.Here providing very low price and Quality ERP,Cloud ERP, CMS , responsive webdesign and ERP. you have any more than information kindly make me call this number 044-42127512 or send your mail

    8. Manage services on SharePoint 2010 servers using PowerShell :

      How to Get from CSV file values(servername,status,type) using Powershell?.

      1. i am control values are csv file oly so how to write script


    9. شركة كشف تسربات المياه

      شركة البيت السعيد
      طرق شركة البيت السعيد شركة كشف تسربات المياه في عزل تسربات المياه:
      إذا تسربات المياه قد تكون في الأسطح المشربة بمياه الأمطار أو مياه الخزانات إذا كانت الخزانات تسرب المياه ، وفي هذا الحالة فإن شركة البيت السعيد شركة كشف تسربات المياه تقوم بـ عزل الأسطح بمادة الفوم وهي من المواد المفضلة لدى الجميع، حيث إن الفوم خفيف الوزن، ويتميز بالعزل الحراري والمائي معًا.
      شركة كشف تسربات المياه بالرياض

      البيت السعيد
      للاستفسار عن جميع خدمات البيت السعيد عزل مائي و عزل حراري و عزل اسطح و عزل خزانات و عزل فوم وجميع انواع العوازل و رش مبيد و مكافحة حشرات و تسليك مجاري و كشف تسربات المياه
      و فحص فلل
      و صيانة مباني و ترميم منازل و نقل عفش و اثاث بالرياض يرجي الاتصال على 0543578920
      او زورو موقعنا على الانترنت