Provisioning SharePoint 2016 Service Applications using Powershell

The Excel services service application has been removed from 2016 SharePoint and moved into the Office Online Server.  You’ll need to spin up the Office Online Server on a separated server and bind it to your SharePoint farm if you want Excel Services.  This is why you’ll notice that the lines for the Excel Services Web application have been commented out.  Removing those comments, along with modifying the variables that annotate 2016 references (e.g. $searchServerName = “2016APP”) to something with 2013 in it’s name is all you need to do to use this script for a 2013 farm.  The current script is essentially just the 2013 script from this site with a few added enhancements: Database names are all in one easy to edit location, Database names use a prefix that you can modify, or leave “” if you don’t want it.

 

The script below installs the Shared Services in an application pool that it creates named, SharePoint Hosted Services.  It creates a separate application pool for Search.

 

Modify the variables to suit your environment.  Make sure that the managed accounts are created for Contoso\2016SP_SA_AP and Contoso\2016SP_Search_AP.  These are the two identities that SharePoint will use to configure the application pools in IIS.  If they are not already managed service accounts in SharePoint, you should add them via the gui or by running New-SPManagedAccount.

 

You might want to modify the database Prefix to something that suits your environment, too.

#####################################################
# This script replicates most of the functionality found in the SharePoint Products Configuration Wizard with the EXCEPTION of the USER PROFILE SERVICE#####################################################
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

## Settings you may want to change ##
$databaseServerName = "SharePointSQL" #assumes you're using a SQL Alias configured with cliconfg.exe
$searchServerName = "2016APP" #Front end Server that will run central admin, the server you’re on right now
$saAppPoolName = "SharePoint Hosted Services"
$appPoolUserName = "Contoso\2016SP_SA_AP" #This is the service application pool account it is not the farm admin account for Timer and Central admin, sometimes calle#d the farm account, it is not the setup account, or install account

$ssaAppPoolName = "SharePoint Search Service Application Pool"
$SearchappPoolUserName = "Contoso\2016SP_Search_AP"



## Service Application Service Names ##
$accesssSAName = "Access 2010 Services"
$bcsSAName = "Business Data Connectivity Service"
$excelSAName = "Excel Services Application"
$metadataSAName = "Managed Metadata Web Service"
$performancePointSAName = "PerformancePoint Service"
$searchSAName = "SharePoint Server Search"
$stateSAName = "State Service"
$secureStoreSAName = "Secure Store Service"
$usageSAName = "Usage and Health Data Collection Service"
$visioSAName = "Visio Graphics Service"
$WordAutomationSAName = "Word Automation Services"

## Service Application Database Names ##
$DatabasePrefix = "2016_"
$UsageDB = $DatabasePrefix + "Usage"
$BusinessDataCatalogDB = $DatabasePrefix + "BDC"
$MetadataDB = $DatabasePrefix + "MetaData"
$PerformancePointDB = $DatabasePrefix + "PerfPoint"
$searchDB = $DatabasePrefix + "Search"
$SecureStoreServiceAppDB = $DatabasePrefix + "SecureStore"
$WordAutomationDB = $DatabasePrefix + "Word_Automation"

$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

}

Write-Host "Creating Usage Service and Proxy…"
$serviceInstance = Get-SPUsageService
New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName $UsageDB -UsageService $serviceInstance > $null

Write-Host "Creating Access Services and Proxy…"
New-SPAccessServiceApplication -Name $accesssSAName -ApplicationPool $saAppPoolName > $null
Get-SPServiceInstance | where-object {$_.TypeName -eq "Access Database Service"} | Start-SPServiceInstance > $null

Write-Host "Creating BCS Service and Proxy…"
New-SPBusinessDataCatalogServiceApplication -Name $bcsSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $BusinessDataCatalogDB > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "Business Data Connectivity Service"} | Start-SPServiceInstance > $null

<#
Write-Host "Creating Excel Service…"
New-SPExcelServiceApplication -name $excelSAName –ApplicationPool $saAppPoolName > $null

Set-SPExcelFileLocation -Identity "http://" -ExcelServiceApplication $excelSAName -ExternalDataAllowed 2 -WorkbookSizeMax 10 -WarnOnDataRefresh:$true

Get-SPServiceInstance | where-object {$_.TypeName -eq "Excel Calculation Services"} | Start-SPServiceInstance > $null
#>

Write-Host "Creating Metadata Service and Proxy…"
New-SPMetadataServiceApplication -Name $metadataSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $Metadata > $null

New-SPMetadataServiceApplicationProxy -Name "$metadataSAName Proxy" -DefaultProxyGroup -ServiceApplication $metadataSAName > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "Managed Metadata Web Service"} | Start-SPServiceInstance > $null

Write-Host "Creating Performance Point Service and Proxy…"
New-SPPerformancePointServiceApplication -Name $performancePointSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $PerformancePointDB > $null

New-SPPerformancePointServiceApplicationProxy -Default -Name "$performancePointSAName Proxy" -ServiceApplication $performancePointSAName > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "PerformancePoint Service"} | Start-SPServiceInstance > $null

##START SEARCH

$ssaAppPool = Get-SPServiceApplicationPool -Identity $ssaAppPoolName -EA 0
if($ssaAppPool -eq $null)
{
Write-Host "Creating Search Service Application Pool…"

$SearchappPoolAccount = Get-SPManagedAccount -Identity $SearchappPoolUserName -EA 0
if($SearchappPoolAccount -eq $null)
{
Write-Host "Please supply the password for the Service Account…"
$ssappPoolCred = Get-Credential $SearchappPoolUserName
$SearchappPoolAccount = New-SPManagedAccount -Credential $ssappPoolCred -EA 0
}

$SearchappPoolAccount = Get-SPManagedAccount -Identity $SearchappPoolUserName -EA 0

if($appPoolAccount -eq $null)
{
Write-Host "Cannot create or find the managed account $SearchappPoolUserName, please ensure the account exists."
Exit -1
}

New-SPServiceApplicationPool -Name $ssaAppPoolName -Account $SearchappPoolAccount -EA 0 > $null

}



## Search Specifics, we are single server farm ##

$searchServerName = (Get-ChildItem env:computername).value

$serviceAppName = "Enterprise Search Services"




## Grab the Appplication Pool for Service Application Endpoint ##

$ssaAppPool = Get-SPServiceApplicationPool $ssaAppPoolName

## Start Search Service Instances ##

Write-Host "Starting Search Service Instances..."

Start-SPEnterpriseSearchServiceInstance $searchServerName

Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

## Create the Search Service Application and Proxy ##

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

$searchServiceApp = New-SPEnterpriseSearchServiceApplication -Name $serviceAppName -ApplicationPool $ssaAppPoolName -DatabaseName $searchDB

$searchProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$serviceAppName Proxy" -SearchApplication $searchServiceApp

## Clone the default Topology (which is empty) and create a new one and then activate it ##

Write-Host "Configuring Search Component Topology..."

$appserv = Get-SPEnterpriseSearchServiceInstance -Identity $searchServerName


Get-SPEnterpriseSearchServiceInstance -Identity $appserv


$ssa = Get-SPEnterpriseSearchServiceApplication


$newTopology = New-SPEnterpriseSearchTopology -SearchApplication $ssa


New-SPEnterpriseSearchAdminComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchCrawlComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchContentProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchAnalyticsProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchQueryProcessingComponent -SearchTopology $newTopology -SearchServiceInstance $appserv

New-SPEnterpriseSearchIndexComponent -SearchTopology $newTopology -SearchServiceInstance $appserv


Set-SPEnterpriseSearchTopology -Identity $newTopology



Write-Host "Search Service Application installation Complete!"

##END SEARCH
 

Write-Host "Creating State Service and Proxy…"
New-SPStateServiceDatabase -Name "StateService" -DatabaseServer $databaseServerName | New-SPStateServiceApplication -Name $stateSAName | New-SPStateServiceApplicationProxy -Name "$stateSAName Proxy" -DefaultProxyGroup > $null

Write-Host "Creating Secure Store Service and Proxy…"
New-SPSecureStoreServiceapplication -Name $secureStoreSAName -Sharing:$false -DatabaseServer $databaseServerName -DatabaseName $SecureStoreServiceAppDB -ApplicationPool $saAppPoolName -auditingEnabled:$true -auditlogmaxsize 30 | New-SPSecureStoreServiceApplicationProxy -name "$secureStoreSAName Proxy" -DefaultProxygroup > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "Secure Store Service"} | Start-SPServiceInstance > $null

Write-Host "Creating Visio Graphics Service and Proxy…"
New-SPVisioServiceApplication -Name $visioSAName -ApplicationPool $saAppPoolName > $null

New-SPVisioServiceApplicationProxy -Name "$visioSAName Proxy" -ServiceApplication $visioSAName > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "Visio Graphics Service"} | Start-SPServiceInstance > $null


Write-Host "Creating Word Conversion Service and Proxy…"
New-SPWordConversionServiceApplication -Name $WordAutomationSAName -ApplicationPool $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName $WordAutomationDB -Default > $null

Get-SPServiceInstance | where-object {$_.TypeName -eq "Word Automation Services"} | Start-SPServiceInstance > $null
############################################## End Script



#Now proceed to manually configuring your service applications (e.g. the Secure Store Service for Visio graphics and performance point. The managed meta data service #for a content type hub)

After the script completes, you’ll want to add the unattached service accounts for Visio Graphics and Performance Point after you create a Secure Store target ID for each.  Although, you can do this via the configuration for each of these service applications in 2016 SharePoint.