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:

image

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:

image

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

    image

    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"
        try
        {
            $serviceinstance | Stop-SPServiceInstance -Confirm:$false
        }
        catch { Write-Host "There was an error:" $_ }
    }
    else
    {
        Write-Host "Managed Metadata Web Service on PAC-SP2010 has already been stopped"
    }

    39 comments:

    1. Very Nice Friends..

      i am From colombia and you Blog very nice.


      THKS

      Andres Franco

      ReplyDelete
    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?

      Thanks

      ReplyDelete
    3. Maybe something like this:

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

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

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

      ReplyDelete
    6. great information !

      ReplyDelete
    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 info@excelanto.com.

      ReplyDelete
    8. Manage services on SharePoint 2010 servers using PowerShell :

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

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

        Delete

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

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

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

      http://www.elbaytelsaeed.com/2017/07/05/%d8%b4%d8%b1%d9%83%d8%a9-%d8%b9%d8%b2%d9%84-%d8%ad%d8%b1%d8%a7%d8%b1%d9%8a-%d8%a8%d8%a7%d9%84%d8%b1%d9%8a%d8%a7%d8%b6-%d8%a7%d9%84%d8%a8%d9%8a%d8%aa-%d8%a7%d9%84%d8%b3%d8%b9%d9%8a%d8%af-0543578920/ 

      ReplyDelete
    10. If you have a history of illness that is difficult to recover, maybe our next article will help you to recover

      Obat gonore
      Obat Kudis
      Obat tipes
      Obat nyeri panggul
      Obat tetanus

      ReplyDelete
    11. Most global offering pays partly and Pitney Bowes corporation. Find out clears in brand new window case or tabWe supply 90 Day service contract entirely contrary to manufacturers flaws. If a physical product does not need to element compared path of the car maker's demands(Otherwise go well with your opportunity classification), It is usually came or maybe a sold during 90 days.

      By maillot de foot pas cher way of Maglie Poco Prezzo writing your company's offer, You are investing buy this valuable equipment from the vendor if you're successful prospective buyer. You Maillot De Foot Pas Cher read and consent to the worldwide hummel trikots transport device fine prints clears in a replacement display maybe loss. Signific expenses previous quotation tend to cause to undergo change should improve you the highest juegos de futbol wager range..

      Through process of presenting the say, You are maillot de foot personnalise investing in buy the following supplement from the amazon müller trikot owner if you're the outstanding prospective buyer. You read and accept the worldwide supply system finer points starts up in dfb trikot müller any kind of time frame or simply tabs. manuel neuer trikot rot Scan debts years ago quotation have been short sale change must heighten Maglie Calcio Poco Prezzo you the optimum buy money.

      ReplyDelete
    12. Business loans are a one of a kind subsidizing technique. It's a buy of future Mastercard deals, not an advance, so we need to utilize particular dialect steady with buy of future Visa deals, similar to payback rate and rebate rate rather than normally utilized financing cost on bank credits. Cash Advances Chicago

      ReplyDelete
    13. If you have a history of illness that is difficult to recover, maybe our next article will help you to recover

      Walatra Berry Jus
      Walatra sehat mata
      Qnc jelly gamat
      Obat Kutil Kelamin Pada Pria & Wanita
      Obat Infeksi Jamur Di Selangkangan

      ReplyDelete
    14. It is a time consuming process to locate a legitimate, high-quality designer Michael Kors Handbags On Sale at a decent price. One brand name that is sought after is the Michael Kors Bags On Sale. Anywhere you see high demand you will find people out to make a quick buck.

      ReplyDelete
    15. It is a time consuming process to locate a legitimate, high-quality designer Michael Kors Handbags Clearance at a decent price. One brand name that is sought after is the Michael Kors Outlet Store. Anywhere you see high demand you will find people out to make a quick buck.

      ReplyDelete
    16. There are those who want to collect vintage items like Michael Kors Factory Outlet with genuine and high quality leathers from Michael Kors. To be able to grab a quality Michael Kors Bags Outlet item of your choice, make sure to be very careful in selecting what to buy, how to buy and where to buy the Michael Kors Outlet Online.

      ReplyDelete
    17. Designer Exposure es un buen lugar para comprar su Bolsos Michael Kors original.
      The Woven Tote es también una selección impresionante en el Bolsos Michael Kors Baratos.
      Bolso de alta calidad que debe contemplar absolutamente un Bolsos Michael Kors Outlet.
      Du kommer att upptäcka en handfull detaljer som du kan förvänta dig att komma över på en vanlig Michael Kors Rea.
      Du kan hitta ett antal platser som ger Väska Michael Kors.
      Sortimentet är fantastiskt för alla som letar efter en MK Väska.
      Håll dina ögon öppna för den här säsongens val som kommer att presenteras under bara några månader och det kommer utan tvekan att bli spektakulärt.

      ReplyDelete