Create Search Service Application in SharePoint 2016

by Robi 16. September 2016 16:52

I'm sharing script I use to create Search service application in SharePoint 2016

 

#Add-PSSnapin Microsoft.SharePoint.PowerShell --EA 0

 

## Change these per your environment ##

$databaseServerName="dbserver"

 

################ search servers in farm ################

$wfe1 = ""

$searchServerName = ""

##########################################################

 

 

################ Search information ################

 

$saAppPoolName = "Search_AppPool"

$appPoolUserName = "" #Enter search service app pool

$IndexLocation = "" #Enter location for search Index e.g. I:\Search

$usagaDatabaseName="SP2016_SA_Usage" #Modify database name as needed

$searchDatabaseName="SP2016_SA_Search" #Modify database name as needed

$contactEmail="" #Enter Search contact email

$defaultContenAccessAccount="" #Enter content access account

$defaultContenAccessAccountPassword=ConvertTo-SecureString -AsPlainText -Force '' #Enter content access account password

$windowsService=Get-SPManagedAccount "" #Enter managed account for search services account

$windowsServicePassword=ConvertTo-SecureString -AsPlainText -Force '' #Enter password for search services account

 

## Service Application Names ##

## Included Usage and Health, as it does get provisioned and if you want to define DB name ##

## Also Usage Proxy Status is stopped which cause Search Application Topology to not find Admin Service ##

$searchSAName = "Search_SA" #Modify Search service application name

$usageSAName = "UsageHealth_SA" #Modify Usage service application name

 

##########################################################

 

 

#region Create folders

$scriptBlock={

param(

$IndexLocation

)

$path=$IndexLocation

#Ustvarimo mapo za search index

if(!(test-path $path)){

New-Item -Path $path -ItemType directory

}

else{

Remove-Item $path -Recurse

New-Item -Path $path -ItemType directory

}

}

 

Invoke-Command -ComputerName $wfe1 -ScriptBlock $scriptBlock -ArgumentList $IndexLocation

 

#endregion

 

 

#region Application pool

#Application pool objekt

$saAppPool = Get-SPServiceApplicationPool -Identity $saAppPoolName -EA 0

if($saAppPool -eq $null)

{

Write-Host "Creating Service Application Pool..."

 

$appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0

if($appPoolAccount -eq $null)

{

Write-Host "Please supply the password for the Service Account..."

$appPoolCred = Get-Credential $appPoolUserName

$appPoolAccount = New-SPManagedAccount -Credential $appPoolCred -EA 0

}

 

$appPoolAccount = Get-SPManagedAccount -Identity $appPoolUserName -EA 0

 

if($appPoolAccount -eq $null)

{

Write-Host "Cannot create or find the managed account $appPoolUserName, please ensure the account exists."

Exit -1

}

 

New-SPServiceApplicationPool -Name $saAppPoolName -Account $appPoolAccount -EA 0 > $null

    

}

 

#endregion

 

 

# region Usage service application

Write-Host "Creating Usage Service and Proxy..."

 

$serviceInstance = Get-SPUsageService

 

New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName $usagaDatabaseName -UsageService $serviceInstance > $null

 

$usa = Get-SPServiceApplicationProxy | where {$_.TypeName -like "Usage*"}

$usa.Provision()

 

#endregion

 

 

#region Start services Create search service application

 

Write-Host "Creating Search Service and Proxy..."

 

Write-Host " Starting Services..."

 

Write-Host "Starting service on wfe1" -ForegroundColor Yellow

Start-SPEnterpriseSearchServiceInstance $wfe1

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $wfe1

 

$ssi= Get-SPServiceInstance -Server $wfe1 |?{$_.typename -eq "SharePoint Server Search"}

while(-not($ssi.status -eq "Online"))

{

write-host -ForegroundColor Yellow $ssi.status;sleep 5;

$ssi=Get-SPServiceInstance -Server $wfe1 |?{$_.typename -eq "SharePoint Server Search"}

}

 

$sqs= Get-SPServiceInstance -Server $wfe1 |?{$_.typename -eq "Search Query and Site Settings Service"}

while(-not($sqs.status -eq "Online"))

{

write-host -ForegroundColor Yellow $sqs.status;sleep 5;

$sqs=Get-SPServiceInstance -Server $wfe1 |?{$_.typename -eq "Search Query and Site Settings Service"}

}

 

Write-Host "Service on wfe1 started" -ForegroundColor green

 

Write-Host "Starting service on index server" -ForegroundColor Yellow

Start-SPEnterpriseSearchServiceInstance $searchServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

$ssi= Get-SPServiceInstance -Server $searchServerName |?{$_.typename -eq "SharePoint Server Search"}

while(-not($ssi.status -eq "Online"))

{

write-host -ForegroundColor Yellow $ssi.status;sleep 5;

$ssi=Get-SPServiceInstance -Server $searchServerName |?{$_.typename -eq "SharePoint Server Search"}

}

 

$sqs= Get-SPServiceInstance -Server $searchServerName |?{$_.typename -eq "Search Query and Site Settings Service"}

while(-not($sqs.status -eq "Online"))

{

write-host -ForegroundColor Yellow $sqs.status;sleep 5;

$sqs=Get-SPServiceInstance -Server $searchServerName |?{$_.typename -eq "Search Query and Site Settings Service"}

}

 

Write-Host "Service on index started" -ForegroundColor green

 

Write-Host " Creating Search Application..."

$searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $searchDatabaseName

Write-Host "Search Service Application Created"

 

#endregion

 

#region Get Initial topology and create clone

 

$searchInstancewfe1 = Get-SPEnterpriseSearchServiceInstance $wfe1

 

$searchInstanceIndex = Get-SPEnterpriseSearchServiceInstance $searchServerName

 

write-host "Getting initial topology"

$InitialSearchTopology = $searchApp | Get-SPEnterpriseSearchTopology -Active

 

$ssa = Get-SPEnterpriseSearchServiceApplication

 

#gets the active search topology from search service application

$ssa.ActiveTopology

 

Write-Host $ssa.ActiveTopology

 

#To clone the active topology

 

$clone = $ssa.ActiveTopology.Clone()

 

#endregion

 

 

#region Modify default topology and activate

 

############################### Index Server #####################################################################

Write-Host "Starting to configure indexing server" -ForegroundColor Yellow

write-host "Creating Admin Component" -ForegroundColor Yellow

New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex

write-host -ForegroundColor Green "Admin Component Created"

 

write-host "Creating Content Processing component" -ForegroundColor Yellow

New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex

write-host -ForegroundColor Green "Content Processing component Created"

 

write-host "Creating Analyticis Processing Component" -ForegroundColor Yellow

New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex

write-host -ForegroundColor Green "Analyticis Processing Component Created"

 

write-host "Creating Crawl Component" -ForegroundColor Yellow

New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchInstanceIndex

write-host -ForegroundColor Green "Crawl Component Created"

Write-Host "Index server configured ###################################################################" -ForegroundColor Green

 

#=============================== Index Server ===================================================================

 

 

 

############################### WFE1 ############################################################################

 

Write-Host "Configuring WFE1" -ForegroundColor Yellow

New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1

write-host -ForegroundColor Green "Admin Component Created on WFE1"

write-host "Creating Index on WFE1 Component" -ForegroundColor Yellow

New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1 -RootDirectory $IndexLocation

write-host -ForegroundColor Green "Index Component on WFE1 Created"

 

write-host "Creating Query Processing Component on WFE1" -ForegroundColor Yellow

New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchInstancewfe1

write-host -ForegroundColor Green "Query Processing Component on wfe 1 Created"

 

Write-Host "Search components on WFE1 Configured ###################################################################" -ForegroundColor Green

#============================== WFE1 ============================================================================

 

 

 

$clone.Activate()

 

#endregion

 

 

#region Set Active admin component

$ssa | get-SPEnterpriseSearchAdministrationComponent | set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstanceIndex

 

#endregion

 

 

 

#region Create search service proxy

Write-Host " Creating Proxy..."

$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName > $null

#endregion

 

 

#region Set default content access account

write-host " Setting default content access account..."

Set-SPEnterpriseSearchServiceApplication -Identity $searchSAName -DefaultContentAccessAccountName $defaultContenAccessAccount -DefaultContentAccessAccountPassword $defaultContenAccessAccountPassword

#endregion

 

 

#region Set Windows services account

Write-Host " Setting windows service account..."

Set-SPEnterpriseSearchService -Identity $searchSAName -ServiceAccount $windowsService.Username -ServicePassword $windowsServicePassword -ContactEmail $contactEmail

#endregion

 

Write-Host " Search Service Application Provisioned" -ForegroundColor Green

 

#region Delete default inactive topology

Write-Host "Getting inactive topology..."

$inactive=Get-SPEnterpriseSearchTopology -SearchApplication Search_Sa |Where {$_.state -eq "Inactive"}

 

 

Write-Host "Removing Inactive topology..."

Remove-SPEnterpriseSearchTopology -Identity $inactive -Confirm:$false

#endregion

 

 

write-host -foregroundcolor green "################################################################### Search completed ###################################################################"

Tags:

Add comment

Calendar

<<  June 2017  >>
MonTueWedThuFriSatSun
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789

View posts in large calendar

Page List

Month List