Skip Ribbon Commands
Skip to main content

Quick Launch

Todd Klindt's home page > Todd Klindt's SharePoint Admin Blog > Posts > Create SharePoint 2013 Search service application with PowerShell
December 04
Create SharePoint 2013 Search service application with PowerShell

I’ve been doing a lot of SharePoint 2013 install webinars lately. Since SharePoint 2010 I’ve been on a personal mission to eradicate nasty GUIDs from all SharePoint databases. When I’m doing my webinars I demonstrate creating the Search service application with PowerShell instead Central Admin. Not because I have anything against Central Admin, it’s a fine web site. But if you create a Search service application in Central Admin you don’t get to specify databases names. And what happens in SharePoint if you don’t specify a database name, SharePoint puts a damned GUID at the end! Grrrrr. So I use PowerShell to create Search, which allows me to specify a database name, and feel a bit better about myself in the process. It’s a win-win! Here is the script that I use. Notice that it is almost completely stolen from my friend Spence Harbar. I grabbed it from this blog post here. If you find this script helpful, buy Spence a drink the next time you see him. Here it is:

# Based on scripts at http://www.harbar.net/articles/sp2013mt.aspx
# Thanks Spence!

# 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
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!"


If you don’t want to copy and paste it, you can download it here. The script assumes your farm has a Service App app pool named "Default SharePoint Service App Pool." It also doesn’t do a couple of things. You’ll need to change the default content crawl account. By default Search uses the Farm account, which is a really bad idea. Worse than wearing white after labor day. If you follow my service account guidelines you'll change this to sp_content. You should also specify a default Search Center.

After your Search service application is created you should run a full crawl, even if you don't have any content in your farm yet. This will let you know that everything is configured correctly.

Enjoy,
tk

 

ShortURL: http://www.toddklindt.com/createsearch2013

Comments

Works great - thanks!

Super fast and easy - thanks!
 on 12/5/2012 3:47 PM

Re: Works great - thanks!

"Super fast and easy?" That was my nickname in high school!

tk
Todd O. KlindtNo presence information on 12/5/2012 10:04 PM

Error

Do you know why I would be getting this error?

PS C:\Installs\Scripts> $searchProxy = New-SPEnterpriseSearchServiceApplicationP
roxy -Name "$serviceAppName Proxy" -SearchApplication $searchServiceApp
New-SPEnterpriseSearchServiceApplicationProxy : Cannot bind argument to
parameter 'SearchApplication' because it is null.
 on 12/18/2012 10:49 AM

Value cannot be Null

I was getting the error "Value cannot be null"  when I tried the $searchSericeApp = New-SPEnterpriseSearchServiceApplication as well.  I have no null values.
 
Any advice would be appriciated.
 on 12/18/2012 3:46 PM

Spence needs to be buying us a drink!

Especially if you can get this working, the appending of the string "Proxy" probably isn't helping many people getting all the errors with it. Other databases can have the GUID removed for their creation through the GUI. The reality is this very poor of MS and probably laziness under the pressure to ship the product.
 on 12/21/2012 4:09 AM

Used an existing App Pool name in IIS and got this.

Starting Search Service Instances...
Creating Search Service Application and Proxy...
New-SPEnterpriseSearchServiceApplication : Value cannot be null.
Parameter name: applicationPool
At C:\Script\CreateSearchService.ps1:21 char:21
+ $searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppNa ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (Microsoft.Offic...viceApplication:NewSearchServiceApplication) [New-SPEnterpriseSear
   chServiceApplication], ArgumentNullException
    + FullyQualifiedErrorId : Microsoft.Office.Server.Search.Cmdlet.NewSearchServiceApplication
 
New-SPEnterpriseSearchServiceApplicationProxy : Cannot bind argument to parameter 'SearchApplication' because it is null.
At C:\Script\CreateSearchService.ps1:22 char:111
+ ... rchApplication $searchServiceApp
+                    ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpris...pplicationProxy], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchServ
   iceApplicationProxy
 
Configuring Search Component Topology...
You cannot call a method on a null-valued expression.
At C:\Script\CreateSearchService.ps1:26 char:1
+ $clone = $searchServiceApp.ActiveTopology.Clone()
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
New-SPEnterpriseSearchAdminComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:28 char:54
+ New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstan ...
+                                                      ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpriseSearchAdminComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchAdmi
   nComponent
 
New-SPEnterpriseSearchContentProcessingComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:29 char:66
+ New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchS ...
+                                                                  ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpris...essingComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchCont
   entProcessingComponent
 
New-SPEnterpriseSearchAnalyticsProcessingComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:30 char:68
+ New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -Searc ...
+                                                                    ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpris...essingComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewAnalyticsP
   rocessingComponent
 
New-SPEnterpriseSearchCrawlComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:31 char:54
+ New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstan ...
+                                                      ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpriseSearchCrawlComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchCraw
   lComponent
 
New-SPEnterpriseSearchIndexComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:32 char:54
+ New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstan ...
+                                                      ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpriseSearchIndexComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchInde
   xComponent
 
New-SPEnterpriseSearchQueryProcessingComponent : Cannot bind argument to parameter 'SearchTopology' because it is null.
At C:\Script\CreateSearchService.ps1:33 char:64
+ New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchSer ...
+                                                                ~~~~~~
    + CategoryInfo          : InvalidData: (:) [New-SPEnterpris...essingComponent], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.Office.Server.Search.Cmdlet.NewSearchQuer
   yProcessingComponent
 
You cannot call a method on a null-valued expression.
At C:\Script\CreateSearchService.ps1:34 char:1
+ $clone.Activate()
+ ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull
 
Search Done!
 on 12/21/2012 4:47 AM

Null Value Errors

If you're getting a Null Value error anywhere, that means a variable you're referencing isn't set to anything. If you're getting that try echoing out each variable after it's assigned to see if it's set to anything. If it's not, then take the variable assignment part at the beginning off to see what the full error is.

tk
Todd O. KlindtNo presence information on 12/21/2012 9:21 PM

Null values fix

restart the server after putting the SharePoint Farm Account in the local Administrators Group (security token to become active)
 on 12/28/2012 4:02 PM

The Errors You See ...

The way this script is designed, it pulls back all of the search instances into a single variable (array) and tries to use this. This will be seen in environments with multiple servers. Those folks who have it working without modification have implemented it into a single singer environment. For folks who need this to run in multi-server environments, review the assignments from the Get-SPEnterpriseSearchServiceInstance.

You can test it by using the instance that is started.
 on 1/3/2013 4:17 PM

The Errors You See ...


The way this script is designed, it pulls back all of the search instances into a single variable (array) and tries to use this. This will be seen in environments with multiple servers. Those folks who have it working without modification have implemented it into a single singer environment. For folks who need this to run in multi-server environments, review the assignments from the Get-SPEnterpriseSearchServiceInstance.

You can test it by using the instance that is started.

Shannon Bray
MCSM: SharePoint
 on 1/3/2013 4:18 PM
1 - 10Next

Add Comment

Items on this list require content approval. Your submission will not appear in public views until approved by someone with proper rights. More information on content approval.

Title


Body *


Today's date *

Select a date from the calendar.
Please enter today's date so I know you are a real person

Twitter


Want a message when I reply to your comment? Put your Twitter handle here.

Attachments

 

 Please Support my Sponsors