Sunday, March 22, 2015

Create Search Service Powershell

I've not had my search service creation go smoothly for me yet. But the good thing is that I created and deleted the search service numerous times without things going too wrong.  Below is a script I found online mixed with information from Professional SharePoint 2013 Administration and a minor tweak of my own to allow for creation in a farm, not just a local install.

Create Search Service

IMPORTANT! You must run this script on the server in your farm that you want search to be installed. Use your install account to create the search service.

# Get App Pool
$saAppPoolName = "Default SharePoint Service App Pool"

# Search Specifics, we are single server farm
$searchServerName = (Get-ChildItem env:computername).value
$serviceAppName = "Search Service Application"
$searchDBName = "SearchService_DB"


# Grab the Appplication Pool for Service Application Endpoint
$saAppPool = Get-SPServiceApplicationPool $saAppPoolName

# Start Search Service Instances
Write-Host "Starting Search Service Instances..."
Start-SPEnterpriseSearchServiceInstance $searchServerName
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

# Create the Search Service Application and Proxy
Write-Host "Creating Search Service Application and Proxy..."
$searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $saAppPoolName -DatabaseName $searchDBName
$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchServiceApp

# Clone the default Topology (which is empty) and create a new one and then activate it
Write-Host "Configuring Search Component Topology..."
$clone = $searchServiceApp.ActiveTopology.Clone()
$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance -Local
New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance 
New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance 
New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance
$clone.Activate()

Write-Host "Search Done!"

In Central Admin > Application Management > Manage Service Applications. Click on the search service and change the default content access account to sp_content.

Move the index

It's a good idea to move your index off your C: drive so it doesn't take up all your space. The example below moves the index to the D: drive.

I found the script Move-SPEnterpriseSearchIndex.ps1 to move the index. Run this script and then alter the last line to something like this:

Move-SPEnterpriseSearchIndex -SearchServiceName "Search Service Application" -Server "SERVERNAMEHERE" -IndexLocation "D:\SearchIndex"


No comments:

Post a Comment