Re-Provisioning SharePoint Search Service Application using PowerShell

[Fixed]: Re-Provisioning SharePoint Search Service Application

No comments

Loading

In this provisioning SharePoint Search Service Application article, we will learn about how to re-provision the SharePoint search service application using the PowerShell script. Many times, we may be in need that needs to re-provision the search service application or any other service applications that got corrupted or not working anymore due to some technical reasons. For example, if you don’t find the “Indexing Schedule Manager on <Server Name>” timer job on your farm, you must re-provision the search service application.

Description of Get-SPServiceApplication command

In this PowerShell script we will use the “Get-SPServiceApplication”, so, let us learn about it.

The Get-SPServiceApplication cmdlet in PowerShell is used within the context of SharePoint to retrieve information about the service applications in a SharePoint farm. This cmdlet provides details on the various service applications configured in the SharePoint environment, such as Search, Managed Metadata, or User Profile services. It is a valuable tool for administrators who need to manage and monitor the service applications in their SharePoint infrastructure.

Description

The Get-SPServiceApplication cmdlet retrieves one or more service applications in the SharePoint farm. By default, it returns all service applications if no specific parameters are provided. You can use various parameters to filter the results and get detailed information about a specific service application or service application proxy.

Syntax


Get-SPServiceApplication [-Identity ] [-AssignmentCollection ] [-Filter ] [-IncludeCentralAdministration ] [-IncludeInvalidXml ] [-IncludeServiceApplications ]

Parameters

  • -Identity: Specifies the GUID or name of the service application to retrieve. This parameter is optional.
  • -AssignmentCollection: Manages objects for proper disposal. Using this parameter, you can assign objects to a variable and dispose of them after they are no longer needed.
  • -Filter: Allows you to specify a string to filter the results.
  • -IncludeCentralAdministration: Includes Central Administration service applications in the results.
  • -IncludeInvalidXml: Includes service applications with invalid XML in the results.
  • -IncludeServiceApplications: Includes service applications in the results.

Step1: Provisioning SharePoint Search Service Application

Using the below PowerShell command get all service applications from the farm:


Get-SPServiceApplication

The command will list out all service applications with their name and ID from the SharePoint farm.

Step 2:

Now, get the specific service application by the ID parameter or name like below:



####The below script is used to re-provision the SharePoint search service application.

cls

$PSshell = Get-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorVariable err -ErrorAction SilentlyContinue
if($PSshell -eq $null)
{
Add-PSSnapin "Microsoft.SharePoint.PowerShell"
}

$fileName = "ReProvisionSharePointSSA_using_PowerShell"

#'yyyyMMddhhmm yyyyMMdd
$enddate = (Get-Date).tostring("yyyyMMddhhmmss")
#$filename = $enddate + '_VMReport.doc'
$logFileName = $fileName +"_"+ $enddate+"_Log.txt"
$invocation = (Get-Variable MyInvocation).Value
$directoryPath = Split-Path $invocation.MyCommand.Path

$directoryPathForLog=$directoryPath+"\"+"LogFiles"
if(!(Test-Path -path $directoryPathForLog))
{
New-Item -ItemType directory -Path $directoryPathForLog
#Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
#$logPath = $directoryPath + "\" + $logFileName

$logPath = $directoryPathForLog + "\" + $logFileName

$isLogFileCreated = $False

function Write-Log([string]$logMsg)
{
if(!$isLogFileCreated){
Write-Host "Creating Log File..."
if(!(Test-Path -path $directoryPath))
{
Write-Host "Please Provide Proper Log Path" -ForegroundColor Red
}
else
{
$script:isLogFileCreated = $True
Write-Host "Log File ($logFileName) Created..."
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
else
{
[string]$logMessage = [System.String]::Format("[$(Get-Date)] - {0}", $logMsg)
Add-Content -Path $logPath -Value $logMessage
}
}
##############The below code is used to re-provison the search service Application in SharePoint on-premise##################################
#Get-SPServiceApplication -Identity GUID ID, example shown below:

Try
{

$ssa=Get-SPServiceApplication -Identity e2c2be70-6382-4ce7-8a55-ae7dadff5786

#or

#Get-SPServiceApplication -Name service application name, example shown below:

$ssa=Get-SPServiceApplication -Name "Search Service Application"

#Now make sure that the $ssa variable returning the correct object by typing the $ssa in the next line command.
#Once you see the that $ssa is returning the correct search service application details, run the below provision method.
$ssa.Provision()
}
catch
{
 $ErrorMessage = $_.Exception.Message +"in re-provisioning the SSA in SharePoint on-premise!:" 
 Write-Host $ErrorMessage -BackgroundColor Red
 Write-Log $ErrorMessage 
}

##############The below code is used to re-provison the search service Application in SharePoint on-premise - ends here##################################

Note:

  • In the above example, the way we have re-provisioned the SharePoint search service application, we can re-provision any service application from the SharePoint farm, just we need to pass the correct service application name or GUID in the Get-SPServiceApplication command.
  • Until it is needed (or corrupted), do not re-provision any service application.
  • First, run the above script or command in the test server before running it in the prod server.

Summary: Provisioning SharePoint Search Service Application

Thus, in this article, we have learned about how to re-provision the SharePoint search service application using PowerShell script or how to re-provision any SharePoint service applications using the PowerShell script.

See Also: SharePoint PowerShell Tutorials

You may also like the following SharePoint PowerShell tutorials:

Buy the premium version of SharePoint Online & Office 365 administration eBook from here:

Buy SharePoint Online & Office 365 Administration eBook

 

 

About Post Author

Do you have a better solution or question on this topic? Please leave a comment