Tuesday, August 20, 2013

Unprovision duplicate service instances in SharePoint 2013

Recently when I checked one of our SharePoint farms (3 server farm with one WFE server, one Application server and one database server), I noticed that service application instances are not provisioned as we planned.
For an example the “SharePoint Server Search” service instance was running on both WFE and Application servers which should be enabled only in the Application server.
So how can we stop that service instance in the WFE server ? can we do it from the central administration itself ?
Unfortunately we can’t. If we try that way we get the following error

image
Instead of using the central administration, we can use PowerShell. We need to get the correct guid of the service application instance.(in this case we need to unprovision the search service instance of WFE server) . As I explained in this post we can get the id of relevant service application instance
   1: Get-SPServiceInstance | where {$_.Status -eq "online" -and $_.TypeName -eq "SharePoint Server Search" } | Sort TypeName | Format-Table TypeName,Id,Server
I got two results for above query as below.

image
To unprovision the SharePoint server search instance from WFE server, I execute the following command
   1: $sh = Get-SPServiceInstance -Identity "7fbdf7a3-c471-4cd7-ba26-4432236b3bd7"
   2: $sh.Unprovision()
That will disable the Search service instance from WFE server.

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.