Sharepoint 2019 search service application using PowerShell

Ammar 41 Reputation points
2023-02-01T06:45:23.1666667+00:00

Dears,

There is a requirement for me to create SharePoint 2019 Search Application using PowerShell. Kindly if you have any working scripts do share the same.

It will be a single server which will host the search application apart from the 4 servers (2 WFE, 2 APPs).

thanks,

SharePoint Server
SharePoint Server
A family of Microsoft on-premises document management and storage systems.
2,422 questions
SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
11,230 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
3,422 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
3,020 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yi Lu_MSFT 17,611 Reputation points
    2023-02-01T08:35:27.91+00:00

    Hi @Ammar

    The following script creates a search service application in SharePoint 2019 using PowerShell for a stand-alone environment.

    Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
     
    # Specify the Settings for the Search Service Application
    $ServerName = (Get-ChildItem env:computername).value
    $IndexLocation = "D:\Search Index"
    $SearchServiceApplicationName = "Search Service Application"
    $SearchServiceApplicationProxyName = "Search Service Application Proxy"
    $SearchDatabaseServer = "G1SP2019"
    $SearchServiceApplicationDatabase = "SP2019_Search_Service"
     
    $SearchAppPoolName = "Search Service Application pool"
    $SearchAppPoolAccount =  Get-SPManagedAccount "Crescent\SP19_Search"
     
    #Check if Managed account is registered already
    Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists"
    $SearchAppPoolAccount = Get-SPManagedAccount -Identity $SearchAppPoolAccount -ErrorAction SilentlyContinue
    If ($SearchAppPoolAccount -eq $null)
    {
        Write-Host "Please Enter the password for the Service Account..."
        $AppPoolCredentials = Get-Credential $SearchAppPoolAccount
        $SearchAppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
    }
     
    #*** Step 1: Create Application Pool for Search Service Application ****
    #Get the existing Application Pool
    $SearchServiceAppPool = Get-SPServiceApplicationPool -Identity $SearchAppPoolName -ErrorAction SilentlyContinue
    #If Application pool Doesn't exists, Create it
    if (!$SearchServiceAppPool)
    {
        $SearchServiceAppPool = New-SPServiceApplicationPool -Name $SearchAppPoolName -Account $SearchAppPoolAccount
        write-host "Created New Application Pool" -ForegroundColor Green
    }
     
    #*** Step 2: Start Search Service Instances ***
    Start-SPEnterpriseSearchServiceInstance $ServerName -ErrorAction SilentlyContinue
    Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $ServerName -ErrorAction SilentlyContinue
     
    #*** Step 3: Create Search Service Application ****
    # Get the Search Service Application
    $SearchServiceApplication = Get-SPEnterpriseSearchServiceApplication -Identity $SearchServiceApplicationName -ErrorAction SilentlyContinue
    # Create the Search Service Application, If it doesn't exists!
    if(!$SearchServiceApplication)
    {
        $SearchServiceApplication = New-SPEnterpriseSearchServiceApplication -Name $SearchServiceApplicationName -ApplicationPool $SearchServiceAppPool -DatabaseServer $SearchDatabaseServer -DatabaseName $SearchServiceApplicationDatabase
        write-host "Created New Search Service Application" -ForegroundColor Green
    }
     
    #*** Step 4: Create Search Service Application Proxy ****
     #Get the Search Service Application Proxy
     $SearchServiceAppProxy = Get-SPEnterpriseSearchServiceApplicationProxy -Identity $SearchServiceApplicationProxyName -ErrorAction SilentlyContinue
     # Create the Proxy, If it doesn't exists!
    if(!$SearchServiceAppProxy)
    {
        $SearchServiceAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name $SearchServiceApplicationProxyName -SearchApplication $SearchServiceApplication
        write-host "Created New Search Service Application Proxy" -ForegroundColor Green
    }
     
    #*** Step 5: Create New Search Topology
    $SearchServiceInstance = Get-SPEnterpriseSearchServiceInstance -Local
    #To Get Search Service Instance on Other Servers: use - $SearchServiceAppSrv1 = Get-SPEnterpriseSearchServiceInstance -Identity "<Server Name>"
     
    # Create New Search Topology
    $SearchTopology =  New-SPEnterpriseSearchTopology -SearchApplication $SearchServiceApplication
     
    #*** Step 6: Create Components of Search
     
    New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance
     
    New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance
     
    New-SPEnterpriseSearchCrawlComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance
     
    New-SPEnterpriseSearchAdminComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance
     
    #Prepare Index Location
    Remove-Item -Recurse -Force -LiteralPath $IndexLocation -ErrorAction SilentlyContinue
    MKDIR -Path $IndexLocation -Force
     
    #Create Index and Query Components
    New-SPEnterpriseSearchIndexComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance -RootDirectory $IndexLocation
     
    New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $SearchTopology -SearchServiceInstance $SearchServiceInstance
     
    #*** Step 7: Activate the Toplogy for Search Service ***
    $SearchTopology.Activate() # Or Use: Set-SPEnterpriseSearchTopology -Identity $SearchTopology 
    
    

    As you see in the above screen, Provisioning search service application creates 4 databases:  I’m naming them as follows:

    • SP2019_Search_Service – Search Service Administration database stores configuration and topology (It could be better: SP2019_Search_Service_AdminDB”)
    • SP2019_Search_Service_AnalyticReporting- Stores the result of usage analysis report.
    • SP2019_Search_Service_CrawlStore – The crawl database contains detailed tracking and historical information about crawled items
    • SP2019_Search_Service_LinksStore – Link database, Stores the information extracted by the content processing component & click-through information of searched items.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.