SharePoint Brew
The official blog of Russ Maxwell, Microsoft SharePoint Premier Field Engineer

SharePoint 2010 Configuring Search Service Application using PowerShell

SharePoint 2010 Configuring Search Service Application using PowerShell

Rate This
  • Comments 19

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"

Leave a Comment
  • Please add 6 and 3 and type the answer here:
  • Post
  • 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.

  • 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

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

  • 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

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

    Thanks!

    Russ

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

  • 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

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

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

  • 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

  • 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

  • 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,

  • 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.

  • 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

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

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

Page 1 of 2 (19 items) 12