Start the SPService instance in SharePoint 2010 using Powershell

 

Steps Involved:

 

1.       Create the input xml file which contains the inputs for starting service instance.

2.       Create ps1 file which contains the script for starting service instance.

StartSPServiceInstance.xml:


<?
xml version="1.0" encoding="utf-8"?>

<StartSPServiceInstance>Service Instance</StartSPServiceInstance>

StartSPServiceInstance.ps1:

## -------------------------------------------------------------------

## Master Powershell script for starting service instance for a service

## Note:- Need to update the XML file path before running the script.

## Author   :

## Date           : 31-Oct-2011

## -------------------------------------------------------------------

 

#----------------Get the xml file---------------------------------------------------------------

 

[xml]$xmlData=Get-Content "D:\Vijai\POCScripts\StartSPServiceInstance.xml"   

$serviceInstanceName=$xmlData.StartSPServiceInstance

 

 

#----------------Start the service instance for a service------------------------------------------------------------

 

Function StartSPServiceInstance()

{

      ## Get the SPService instance from the current server

      $serviceInstance=Get-SPServiceInstance |  ? {$_.TypeName -eq $serviceInstanceName}

      ## Check whether the service instance is available in the server

      if($serviceInstance -ne $null)

      {

          ## Check whether the service instance status is "Online" or "Disabled"

            if($serviceInstance.Status -eq "Disabled")

            {

                  Write-Host -ForegroundColor Magenta $serviceInstanceName " service instance is starting....."

                  ## If the service instance status is "Disabled" start the service instance

                  Start-SPServiceInstance $serviceInstance | Out-Null  

                  while($serviceInstance.Status -ne "Online")

                  {                      

                        $serviceInstance=Get-SPServiceInstance |  ? {$_.TypeName -eq $serviceInstanceName}

                  }

                  Write-Host -ForegroundColor Green $serviceInstanceName " service instance is started"

            }

            else

            {

            Write-Host -ForegroundColor Yellow $serviceInstanceName " service instance is already started"

            }

      }

      else

      {

            Write-Host -ForegroundColor Yellow $serviceInstanceName " service instance does not exists"      

      }

}

 

#----------------Calling the function------------------------------------------------------------

StartSPServiceInstance

 

Run the Script:

 

1.       Go to Start.

2.       Click on All Programs.

3.       Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell (run as Administrator).

4.       Run the D:\Vijai\POCScripts\StartSPServiceInstance.ps1