SharePoint 2010 Configuring Search Service Application using PowerShell


NOTE:  This has been updated as of 2/2/2010!   This has only been tested against SharePoint 2010 “without Fast integrated”.  Thanks to Jon Waite for cleaning up some of these steps.

It might be necessary at some point to use PowerShell to provision search service applications.  For Example, setting up a search service application for hosted sites requires you to use PowerShell.  The following steps manually take you through this process and I highly recommend going through the steps to become more familiar with the command-lets.  ​ A sample powershell script is provided at the bottom of this blog. 

Creating Search Service Application using PowerShell

1. Create Application Pool

Creating a an application pool for your search service application and throwing the object into a variable called $ app:

      $app = new-spserviceapplicationpool –name contososearch-apppool –account domain\user

 

2. Create search service application

      $searchapp = new-spenterprisesearchserviceapplication -name ContosoSearchServiceApplication -applicationpool $app

Note: Add the -partitioned switch after -name if the search service application will be consumed in a hosted environment.                        

 

3. Create search service application proxy

$proxy = new-spenterprisesearchserviceapplicationproxy -name Contososearchserviceapplicationproxy -Uri $searchapp.uri.absoluteURI

            Note: Add the -partitioned switch if the search service application will be consumed in a hosted environment.

Verify the search service application proxy is online.  It should be online by default..

$proxy.status 

If it’s not online, you can change the status by punching in the following:

To change this property you could type something like this:

$proxy.status = “online”

Finally, you must update the change by calling the update method.

$changestatus.update()

 

4.  Ensure the local search service instance is started

Run the following: 

$si = get-spenterprisesearchserviceinstance –local

$si.status

If it’s enabled/started, skip to step 5!

If it’s disabled then run the following:

Start-SpEnterpriseSearchServiceInstance -identity $SI

 

5.  Provision Search Administration Component

Configure the administration component of the associated Searchserviceapplication.  You can do this with the following command:

set-spenterprisesearchadministrationcomponent –searchapplication $searchapp  –searchserviceinstance $si

 

6. Provision Crawl Component and Activate

By default, a search application created in PowerShell has a crawl topology but is missing the following:

· crawl component           

· query component

You cannot add a crawl\query component to the default crawl\query topology because it’s set as active and the property is read only.  The easiest way around this is creating a new crawl topology and new query topology.  After creating both, they will be set as inactive by default.  This allows for both crawl components to be added to crawl topology and query component to be added to newly created query topology. Finally, you can set this new crawl topology to active. 

 

a. Create Crawl Topology

$ct = $searchapp | new-spenterprisesearchcrawltopology

 

b. Create a new Crawl Store

$csid = $SearchApp.CrawlStores | select id

$CrawlStore = $SearchApp.CrawlStores.item($csid.id)

 

c. Create a new Crawl Component

Create a crawl component for new crawl topology by passing the variables representing the crawl topology, search instance, and crawlstore.

$hname = hostname

new-spenterprisesearchcrawlcomponent -crawltopology $ct -crawldatabase $Crawlstore -searchserviceinstance $hname

 

d. Finally, set the new crawl topology as active.

$ct | set-spenterprisesearchcrawltopology -active

 

7.  Create Query Components and Activate

a. Create a new Query Topology 

$qt = $searchapp | new-spenterprisesearchquerytopology -partitions 1

 

b. Create a variable for the Query Partition

$p1 = ($qt | get-spenterprisesearchindexpartition)

 

c. Create a new Query Component

new-spenterprisesearchquerycomponent -indexpartition $p1 -querytopology $qt -searchserviceinstance $si

 

d. Create a variable for the Property Store DB

$PSID = $SearchApp.PropertyStores | Select id

$PropDB = $SearchApp.PropertyStores.Item($PSID.id)

 

e. Set the Query Partition to use the Property Store DB

$p1 | set-spenterprisesearchindexpartition -PropertyDatabase $PropDB

 

f.  Activate the Query Topology

$qt | Set-SPEnterpriseSearchQueryTopology -Active

 

==========================================================

Sample Script

Thanks is in store to Colin at MSFT for taking the cmdlets above and throwing together a great sample script.   Copy the script below and save it as a .PS1 file.  

Note:  When provisioning a search service application for hosted “multi-tenant” sites, the following cmd-lets must contain the –partitioned parameter.

  • New-SPEnterpriseSearchServiceApplication (Step 3 below)
  • New-SPEnterpriseSearchServiceApplicationProxy (Step 4 below)

 

Add-PSSnapin Microsoft.SharePoint.PowerShell

# 1.Setting up some initial variables.
write-host 1.Setting up some initial variables.
$SSAName = “ContosoSearch”
$SVCAcct = “Contoso\administrator”
$SSI = get-spenterprisesearchserviceinstance -local
$err = $null

# Start Services search services for SSI
write-host Start Services search services for SSI
Start-SPEnterpriseSearchServiceInstance -Identity $SSI

# 2.Create an Application Pool.
write-host 2.Create an Application Pool.
$AppPool = new-SPServiceApplicationPool -name $SSAName”-AppPool” -account $SVCAcct

# 3.Create the SearchApplication and set it to a variable
write-host 3.Create the SearchApplication and set it to a variable
$SearchApp = New-SPEnterpriseSearchServiceApplication -Name $SSAName -applicationpool $AppPool -databasename $SSAName”_AdminDB”

#4 Create search service application proxy
write-host 4 Create search service application proxy
$SSAProxy = new-spenterprisesearchserviceapplicationproxy -name $SSAName”ApplicationProxy” -Uri $SearchApp.Uri.AbsoluteURI

# 5.Provision Search Admin Component.
write-host 5.Provision Search Admin Component.
set-SPenterprisesearchadministrationcomponent -searchapplication $SearchApp  -searchserviceinstance $SSI

# 6.Create a new Crawl Topology.
write-host 6.Create a new Crawl Topology.
$CrawlTopo = $SearchApp | New-SPEnterpriseSearchCrawlTopology

# 7.Create a new Crawl Store.
write-host 7.Create a new Crawl Store.
$CrawlStore = $SearchApp | Get-SPEnterpriseSearchCrawlDatabase

# 8.Create a new Crawl Component.
write-host 8.Create a new Crawl Component.
New-SPEnterpriseSearchCrawlComponent -CrawlTopology $CrawlTopo -CrawlDatabase $CrawlStore -SearchServiceInstance $SSI

# 9.Activate the Crawl Topology.
write-host 9.Activate the Crawl Topology.
do
{
    $err = $null
    $CrawlTopo | Set-SPEnterpriseSearchCrawlTopology -Active -ErrorVariable err
    if ($CrawlTopo.State -eq “Active”)
    {
        $err = $null
    }
    Start-Sleep -Seconds 10
}
until ($err -eq $null)

# 10.Create a new Query Topology.
write-host 10.Create a new Query Topology.
$QueryTopo = $SearchApp | New-SPenterpriseSEarchQueryTopology -partitions 1

# 11.Create a variable for the Query Partition
write-host 11.Create a variable for the Query Partition
$Partition1 = ($QueryTopo | Get-SPEnterpriseSearchIndexPartition)

# 12.Create a Query Component.
write-host 12.Create a Query Component.
New-SPEnterpriseSearchQueryComponent -indexpartition $Partition1 -QueryTopology $QueryTopo -SearchServiceInstance $SSI

# 13.Create a variable for the Property Store DB.
write-host 13.Create a variable for the Property Store DB.
$PropDB = $SearchApp | Get-SPEnterpriseSearchPropertyDatabase

# 14.Set the Query Partition to use the Property Store DB.
write-host 14.Set the Query Partition to use the Property Store DB.
$Partition1 | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $PropDB

# 15.Activate the Query Topology.
write-host 15.Activate the Query Topology.
do
{
    $err = $null
    $QueryTopo | Set-SPEnterpriseSearchQueryTopology -Active -ErrorVariable err -ErrorAction SilentlyContinue
    Start-Sleep -Seconds 10
    if ($QueryTopo.State -eq “Active”)
        {
            $err = $null
        }
}
until ($err -eq $null)

Write-host “Your search application $SSAName is now ready”


Comments (23)

  1. Pankaj Jain says:

    I really appriciate if you will provide me the details of configuring search in 2010.I already configured search in 2007 but in 2010 there is no concept of SSP.That’s the reason,i want to know how to configure search in 2010.

  2. Russ Maxwell says:

    Yup, these steps worked prior to beta 2!!  I’m going to update this blog soon to have the correct cmdlets to make this go…  Stay tuned…

    Russmax

  3. Tom Hockman says:

    Does provisioning search in 2010 have to be this complicated? If so, why? This seems a huge step backward toward configuring search.

  4. Russ Maxwell says:

    Don’t worry, Search doesn’t have to be this complicated.  The reason why you would go with PowerShell eventhough it seems more complicated is that you can group these cmdlets into a script which can ultimately make deploying Search Service Application faster.  The easy way to provision a Search Service Application involves using the "UI" by accessing the Manage Service Application page within Central Administrator.

    FYI… The blog has been updated and should provide a better result for beta 2 builds…

    Thx,

    Russmax, MSFT

  5. Russ Maxwell says:

    Good news…  This blog has been updated and will not work with Beta 2 build but should work with any later build…

    Thanks!

    Russ

  6. donal.conlon says:

    Is there any control over the database names for the crawl and property stores?

  7. GilbertoZ says:

    I’m strongly interested in any PowerShell configuration procedure for the many Service Applications; do you intend provide us with some sample like this (amazing!).

    If not, could you suggest me any link where I could find such descriptions?

    Thanks in advance

  8. Purna chander.M says:

    How to configure Search in Sharepoint 2010.In SP2010 there is no concept of Shared Service Provider(SSP) Is that needs SOA knowledge??

  9. Which database server is used? Will the "Default database server" be selected?

  10. tbithell says:

    I keep getting a databast timeout error when trying to configure search.  The configuration wizard, central admin, and powerhell all get this error.  Are you aware of any way to bump up the database timout time?  I found this article, and while it looks like it works in my uls log I see a connection string that says the connection timeout is set to 15 seconds.

    technet.microsoft.com/…/cc263314(office.12).aspx

  11. tbithell says:

    I keep getting a database timeout error when trying to configure search.  The configuration wizard, central admin, and powerhell all get this error.  Are you aware of any way to bump up the database timout time?  I found this article, and while it looks like it works in my uls log I see a connection string that says the connection timeout is set to 15 seconds.

    technet.microsoft.com/…/cc263314(office.12).aspx

  12. AnujG says:

    thanks for this script. I am able to create an SSA. but when i view the properties of this SSA in UI, then under FAST Service application i see the option selected as None (available are None, FAST Search Connector & FAST Search Query). The other 2 options are greyed out.

    Could you please tell how can i modify these parameters?

    If i create an SSA thru UI, then i am able to modify the options.

    thanks,

  13. Keith Caravelli says:

    I am experimenting on how to "tune" search with PowerShell. I am really interested in the many ways to add Scopes, Best Bets and Managed Properties with PS so that tuning search can be something I do on the fly after a periodic review of the Search Query Reports. This is what will help my users get more out of search.  As in other areas, I am also curious to see what added functionality PS exposes beyond the Search GUI. I find that normally when I use PS I get so much more out of the feature set just because they did not feel like cramming all that stuff in the GUI and rightly so.

  14. Thomas says:

    don't forget to start Search Query and Site Settings Service … or your search application will look great in central administration, but your search center throws an error

    Get-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance -Local | Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance

  15. Gyorgy Herman says:

    The line $changestatus.update() , i think is wrong. The $changestatus object was not defined previously,

    I think $proxy.update(),  should be used instead.

  16. Andrei Vassiliev says:

    This script worked for me multiple times, but today it got stuck on "9.Activate the Crawl Topology." Any idea, anyone?

  17. Scott Davis says:

    I commented yesterday.  I made a mistake the Databases are created but step 15 has run over night and still has not errored out or completed successfully.

    Regards,

    Scott Davis

    Spdavis@hntb.com

  18. shobs says:

    This script is stuck on step 15. Any idea?

  19. Mark Dordoy says:

    I am also seeing the script stay on step 15 without completing.

  20. Michelle Church says:

    Did anyone who reported the "Stuck on step 15" get it resolved and, if so, what was the resolution?

  21. Steve H says:

    Hi Russmax,

    I ran all the powershell and it seemed to work – the search admin pages in central admin are all there and i kicked off a crawl…

    So next I ran a search from the root sites in all web apps that now use this new search application and every site gave an error – here is one:

    Error

    Internal server error exception:

    Troubleshoot issues with Microsoft SharePoint Foundation.

    Correlation ID: 9755cf7c-dd87-4a19-abf0-9959faa3c510

    Date and Time: 12/28/2012 8:33:01 PM

    I have not yet looked in the logs but is there another step not listed above?

    Maybe a step where you tell the site collection to use the newly made search app….?

    The web app knows about the search app but the actual search run from a site collection does not work…!

    Any idea what I might have missed?

    Thanks,

    Steve

  22. Parag says:

    Can you guide us how to avoid creation of mutliple search service application using powershell

  23. Andre says:

    Is there a way to use the Set-SPEnterpriseSearchCrawlTopology to make an topology Inactive?

    Thanks