List All Services in a SharePoint Farm

If you were to manually open Central Administration (pfff who does that now that PowerShell exists), and were to navigate to the System Settings subsection, under the Manage services​ on server option, you would find a list of all services that are available in your SharePoint farm, and their status (Started or Stopped). From that page, you are also provided with the ability to manually turn each service instance On or Off. Using PowerShell, this can also be easily achieved with only a few lines of code.

To begin, we need to get a reference to the current SPServer object. Remember that service instances in the SharePoint world are associated with a specific SharePoint server. If you had a farm with 3 servers in it, you could make a decision to run the Search Service for example on two of them but don’t have it run on the third one. Using the Get-SPServer cmdlet, we retrieve the list of all servers in our farm (see Figure 1).

$servers = Get-SPServer


Figure 1 – Retrieving a list of all SharePoint servers in the SharePoint farm using PowerShell

Once the list of SharePoint server is obtained, we can access any SPServer object directly from the collection of server obtained, and then retrieve the ServiceInstances property from it. This will return a collection of SPServiceInstance objects where each item contained in it represent a specific service (see Figure 2).

$services = ​$servers[0].ServiceInstance


Figure 2 – Listing all SharePoint Service Instances of a specific SharePoint Server using PowerShell

The status column, even though it shows Online and Disabled as statuses, really represents the Started and Stopped​ statuses we are seeing through the Central Aministration web interface. You can retrieve the instance of a specific service instance by simply Querying the collection object (see Figure 3). For example, if I wanted to retrieve an instance of the Visio Graphis Service I could simply execute the following line of code:

$visioService = ​$services | Where{$_.TypeName -like “*Visio*”}


Figure 3 –  Obtaining a reference to the SharePoint Visio Graphics Service Instance using PowerShell

Once you have obtained a reference to a service instance, you can start or stop it by setting its Status property. However, doing so is not as simple as simply setting it to a boolean (true or false). It requires you to actually set it to a Microsoft.SharePoint.Administration.SPObjectStatus object valid status (in string). This object is actually an enumeration of various statuses:

  • ​Online
  • Disabled
  • Provisioning
  • Upgrading​
  • Unprovisioning
  • Offline
We are really only interested in the two first items. In my example (Visio Graphics Service), if I wanted to enable the service on my server, I would do it using the following line of PowerShell code (see Figure 4).
​$visioService.Status = “Online”
Figure 4 – ​​Visio Graphics Services Enabled via PowerShell for SharePoint 2013

Leave a Reply

Your email address will not be published. Required fields are marked *