Friday, August 16, 2013

Why do I get multiple results for each service instance in Get-SPServiceInstance?

Let’s assume that we have a multi-server SharePoint 2013 farm with one or more WFE servers and one or more Application servers.
If we need to do something with service application instances, we normally use the PowerShell  “Get-SPServiceInstance” command. For a certain task I needed to do some modifications to “Search Host Controller Service”. So I executed following command.
   1: $sh = Get-SPServiceInstance | ? {$_.TypeName -eq "Search Host Controller Service"}
To verify the result I got, I executed following command to get the id of service application instance.
   1: $sh.id
But surprisingly I got 2 ids.

image

Does that mean that I have 2 active Search Host Controller Service service instances running?. and what is the relevant Guid for my next commands?

To clarify doubts let’s think how service applications/service application instances are kept in SharePoint. When we install SharePoint in a server new service application instances are created. But they may not be in active state. We can easily see that from the services on this server section in central administration.

image

But how can I get other information like their guids. We can use PowerShell to easily get that info. We can start with a script like below.
   1: Get-SPServiceInstance | Sort TypeName | Format-Table TypeName,Id,Server
You can see following results

image

As you can see I have 2 copies of each service application instances. That is because I have 2 SharePoint servers in my farm. So how can I know which service application instance(s) are running at the moment. We need to modify our script a little bit.
   1: Get-SPServiceInstance | Sort TypeName | Format-Table TypeName,Id,Status,Server
Now we can see service instances with their status as below

image

As you can see not all service application instances are in Online state. In our next modification to the script we will filter all Online services
   1: Get-SPServiceInstance | where {$_.Status -eq "online" } | Sort TypeName | Format-Table TypeName,Id,Status,Server
The result will be as below

image

As I needed the guid of online “Search Host Controller Service” instance I can easily get from above or I can modify the where clause to input the TypeName to return only the specific service application instance.

No comments: