Search Our Site

Create an Account

SharePoint Server Powershell Reference

SharePoint Server 2016
Start-SPEnterpriseSearchServiceInstance $env:COMPUTERNAME -ErrorAction SilentlyContinue Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $env:COMPUTERNAME -ErrorAction SilentlyContinue

$sa = New-SPEnterpriseSearchServiceApplication -Name "Search Service Application" -DatabaseName "Search_Service_DB" -ApplicationPool "Default SharePoint Service App Pool" -AdminApplicationPool "Default SharePoint Service App Pool"
New-SPEnterpriseSearchServiceApplicationProxy -Name "Search Service Application" -SearchApplication $sa
$si = Get-SPEnterpriseSearchServiceInstance -Local
$clone = $sa.ActiveTopology.Clone()

New-SPEnterpriseSearchAdminComponent -SearchTopology $clone -SearchServiceInstance $si
New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $clone -SearchServiceInstance $si
New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $clone -SearchServiceInstance $si
New-SPEnterpriseSearchCrawlComponent -SearchTopology $clone -SearchServiceInstance $si
New-SPEnterpriseSearchIndexComponent -SearchTopology $clone -SearchServiceInstance $si -IndexPartition 0
New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $clone -SearchServiceInstance $si

#Finally, remove the inactive topologies.
$sa = Get-SPEnterpriseSearchServiceApplication
foreach($topo in (Get-SPEnterpriseSearchTopology -SearchApplication $sa | ?{$_.State -eq "Inactive"})){Remove-SPEnterpriseSearchTopology -Identity $topo -Confirm:$false}

#Set the Crawl Account for the Search Service Application.
$sa = Get-SPEnterpriseSearchServiceApplication
$content = New-Object Microsoft.Office.Server.Search.Administration.Content($sa)
$content.SetDefaultGatheringAccount("DOMAIN\SP_Crawl", (ConvertTo-SecureString "password" -AsPlainText -Force))

#Set the Full Crawl schedule of the Local SharePoint sites Content Source.
$source = Get-SPEnterpriseSearchCrawlContentSource -SearchApplication $sa -Identity "Local SharePoint sites"
Set-SPEnterpriseSearchCrawlContentSource -Identity $source -ScheduleType Full -WeeklyCrawlSchedule -CrawlScheduleRunEveryInterval 1 -CrawlScheduleDaysOfWeek "Sunday" -CrawlScheduleStartDateTime "03:00 AM"


Monitoring the status of your farm's health is a critical aspect of SharePoint Administration. This service application collects various logging information stored in SharePoint and writes it to the logging database. This service application should always be created in your farm.
New-SPUsageApplication -Name "Usage and Health Data Collection"

$proxy = Get-SPServiceApplicationProxy | where {$_.TypeName -eq "Usage and Health Data Collection Proxy"}



With the arrival of SharePoint 2016, farm configuration changed a bit. A new feature was added which allows you to choose the role of the server when you create a new SharePoint farm, or when you are joining a server to an existing farm. This feature is called MinRole. In PowerShell, there are 2 cmdlets which are involved in the creation of a farm or in the joining in an existing farm. Below you will see the PowerShell commands for creating a new farm using the New-SPConfigurationDatabase cmdlet.

MinRole Variables: WebFrontEnd, Application, SingleServerFarm, DistributedCache, Search, Custom, ApplicationWithSearch (Only available with November 2016 Patch installed), WebFrontEndWithDistributedCache (Only available with November 2016 Patch installed)
#Specify SharePoint Configuration variables
$ConfigDatabaseName = “SharePoint_Config_DB”
$SQLServer = “”
$CADatabaseName = “SharePoint_Admin_DB”
$CAPort = 8000
$CAAuth = “NTLM”
$PassPhrase = “Password1”
$LocalServerRole = “SingleServerFarm”
$sPassphrase = (ConvertTo-SecureString -String $passphrase -AsPlainText -force)

#Create new SharePoint Farm
New-SPConfigurationDatabase -DatabaseName $ConfigDBName -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDBName -FarmCredentials $FarmCredential -Passphrase $Passphrase -LocalServerRole $ServerRole

#Run the following commands
Install-SPHelpCollection -All
Install-SPFeature -AllExistingFeatures
New-SPCentralAdministration -Port $CAPort -WindowsAuthProvider NTLM


Run the PowerShell script below to Join an additional server to an existing SharePoint 2016 server. You need to specify the Database Server name and SharePoint Configuration database name in the code below before you execute. Additionally you need to specify the -LocalServerRole

-Local Server Role
ApplicationWithSearch (Only available with November 2016 Patch installed)
WebFrontEndWithDistributedCache (Only available with November 2016 Patch installed)
#Connects Server to Existing Farm
Connect-SPConfigurationDatabase -DatabaseServer SQL01 -DatabaseName SharePoint_Config -Passphrase (ConvertTo-SecureString "password" -AsPlainText -force) -LocalServerRole WebFrontEnd
After you run the script above you need to run code listed below in order to complete the joining of the server to the farm.
#Run the following Commands
Install-SPFeature -AllExistingFeatures
Install-SPHelpCollection -All


New-SPStateServiceApplication -Name "State Service Application"
Get-SPStateServiceApplication | New-SPStateServiceApplicationProxy -defaultproxygroup
Get-SPStateServiceApplication | New-SPStateServiceDatabase -Name "State_Service_DB"
Get-spdatabase | where-object {$_.type -eq "Microsoft.Office.Server.Administration.StateDatabase"} | initialize-spstateservicedatabase


Indy Business Solutions LLC

Avon, Indiana / USA 1.317.285.0645