Service Applications PowerShell

What lies below is my PowerShell script that will create all of the Service Applications typically used in most farms, all with custom database names and some with separate Application pools.  You will need to adjust the names, settings, etc. to suit your environment, but this is a nice shell to get you going.

What is missing?
The User Profile Service Application.  This cannot be setup via PowerShell.  Don't even try it.  Instead setup this Service Application afterwards using the Central Admin GUI.  You will be able to select custom database names here so that all of your databases can have a nice prefix like mine: SP2010_Dev_ and then nice names after that for each function.  Use this guide to setup the User Profile Service:  http://www.harbar.net/articles/sp2010ups.aspx

Script (save the below area in notepad or PowerShell ISE (recommended) and save as .ps1 file extension)  Run this script in SharePoint Management Shell:


<#
This script replicates most of the functionality found in the SharePoint Products Configuration Wizard
It has been customized so that all databases will be formatted as you wish.
No more GUIDs in the database names.

Run this in the SharePoint Management Shell, i.e. PowerShell with SharePoint APIs.

Adjust the Application Pool sections to suit your needs.
I recommend using at least 5 application pools and more when you are creating extra web applications.

This will not configure the User Profile Service Application!!!!
That must be configured in Central Admin or errors will occur.


IMPORTANT:  Create Active Directory Service Accounts for application pools first.
#>


# Settings you may want to change
$databaseServerName     = "sql08r2"
$searchServerName       = "dev-sp2010"
$MainAppPoolName        = "Main App Pool"
$MainAppPoolAcct        = "dev\svc.sp10.pool.main"
$UPSAppPoolName         = "UPS App Pool"
$UPSAppPoolAcct         = "dev\svc.sp10.pool.ups"
$MySitesAppPoolName     = "MySites App Pool"
$MySitesAppPoolAcct     = "dev\svc.sp10.pool.mysite"
$SecureStoreAppPoolName = "Secure Store Svc App Pool"
$SecureStoreAppPoolAcct = "dev\svc.sp10.pool.sss"
$SearchAppPoolName      = "Search App Pool"
$SearchAppPoolAcct      = "dev.local\svc.sp10.pool.search"


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

# Database Names
$dbNameBDC                = "SP2010_Dev_BusinessDataCatalog"
$dbNameMetadata           = "SP2010_Dev_Metadata"
$dbNamePerfPoint          = "SP2010_Dev_PerformancePoint"
$dbNameProfile            = "SP2010_Dev_Profile"
$dbNameSearch             = "SP2010_Dev_Search"
$dbNameSecureStore        = "SP2010_Dev_SecureStoreServiceApp"
$dbNameSocial             = "SP2010_Dev_Social"
$dbNameStager             = "SP2010_Dev_Stager"
$dbNameStateService       = "SP2010_Dev_StateService"
$dbNameSync               = "SP2010_Dev_Sync"
$dbNameUsageService       = "SP2010_Dev_Usage"
$dbNameWarehouse          = "SP2010_Dev_Warehouse"
$dbNameWordAutomation     = "SP2010_Dev_WordAutomation"

Write-Host "Begin installing Application Pools"


# Application Pools

# Create the Main Application Pool
Write-Host -backgroundColor Red "When the Windows PowerShell Credential Request dialog box opens, type the user name and password for the Main Application Pool service account."
$credMainAppPool = Get-Credential
New-SPManagedAccount -Credential $credMainAppPool
New-SPServiceApplicationPool -name $MainAppPoolName -account $MainAppPoolAcct


# Create the User Profile Service Application Pool
Write-Host -backgroundColor Red "When the Windows PowerShell Credential Request dialog box opens, type the user name and password for the User Profile Service Application Pool service account."
$credUPSAppPool = Get-Credential
New-SPManagedAccount -Credential $credUPSAppPool
New-SPServiceApplicationPool -name $UPSAppPoolName -account $UPSAppPoolAcct


# Create the MySites Application Pool
Write-Host -backgroundColor Red "When the Windows PowerShell Credential Request dialog box opens, type the user name and password for the MySites Application Pool service account."
$credMySitesAppPool = Get-Credential
New-SPManagedAccount -Credential $credMySitesAppPool
New-SPServiceApplicationPool -name $MySitesAppPoolName -account $MySitesAppPoolAcct


# Create the Secure Store Service Application Pool
Write-Host -backgroundColor Red "When the Windows PowerShell Credential Request dialog box opens, type the user name and password for the Secure Store Service Application Pool service account."
$credSSSAppPool = Get-Credential
New-SPManagedAccount -Credential $credSSSAppPool
New-SPServiceApplicationPool -name $SecureStoreAppPoolName -account $SecureStoreAppPoolAcct


# Create the Search Application Pool
Write-Host -backgroundColor Red "When the Windows PowerShell Credential Request dialog box opens, type the user name and password for the Search Application Pool service account."
$credSearchAppPool = Get-Credential
New-SPManagedAccount -Credential $credSearchAppPool
New-SPServiceApplicationPool -name $SearchAppPoolName -account $SearchAppPoolAcct




Write-Host "Begin installing Service Applications"

# Service Applications

Write-Host "Creating Usage Service and Proxy..."
$serviceInstance = Get-SPUsageService
New-SPUsageApplication -Name $usageSAName -DatabaseServer $databaseServerName -DatabaseName $dbNameUsageService -UsageService $serviceInstance


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


Write-Host "Creating BCS Service and Proxy..."
New-SPBusinessDataCatalogServiceApplication -Name $bcsSAName -ApplicationPool $MainAppPoolName -DatabaseServer $databaseServerName -DatabaseName $dbNameBDC
Get-SPServiceInstance | where-object {$_.TypeName -eq "Business Data Connectivity Service"} | Start-SPServiceInstance


Write-Host "Creating Excel Service..."
New-SPExcelServiceApplication -name $excelSAName –ApplicationPool $MainAppPoolName
Set-SPExcelFileLocation -Identity "http://" -ExcelServiceApplication $excelSAName -ExternalDataAllowed 2 -WorkbookSizeMax 10 -WarnOnDataRefresh:$true
Get-SPServiceInstance | where-object {$_.TypeName -eq "Excel Calculation Services"} | Start-SPServiceInstance


Write-Host "Creating Metadata Service and Proxy..."
New-SPMetadataServiceApplication -Name $metadataSAName -ApplicationPool $MainAppPoolName -DatabaseServer $databaseServerName -DatabaseName $dbNameMetadata
New-SPMetadataServiceApplicationProxy -Name "$metadataSAName Proxy" -DefaultProxyGroup -ServiceApplication $metadataSAName
Get-SPServiceInstance | where-object {$_.TypeName -eq "Managed Metadata Web Service"} | Start-SPServiceInstance


Write-Host "Creating Performance Point Service and Proxy..."
New-SPPerformancePointServiceApplication -Name $performancePointSAName -ApplicationPool $MainAppPoolName -DatabaseServer $databaseServerName -DatabaseName $dbNamePerfPoint
New-SPPerformancePointServiceApplicationProxy -Default -Name "$performancePointSAName Proxy" -ServiceApplication $performancePointSAName
Get-SPServiceInstance | where-object {$_.TypeName -eq "PerformancePoint Service"} | Start-SPServiceInstance


Write-Host "Creating State Service and Proxy..."
New-SPStateServiceDatabase -Name $dbNameStateService -DatabaseServer $databaseServerName | New-SPStateServiceApplication -Name $stateSAName | New-SPStateServiceApplicationProxy -Name "$stateSAName Proxy" -DefaultProxyGroup

Write-Host "Creating Secure Store Service and Proxy..."
New-SPSecureStoreServiceapplication -Name $secureStoreSAName -Sharing:$false -DatabaseServer $databaseServerName -DatabaseName $dbNameSecureStore -ApplicationPool $SecureStoreAppPoolName -auditingEnabled:$true -auditlogmaxsize 30 | New-SPSecureStoreServiceApplicationProxy -name "$secureStoreSAName Proxy" -DefaultProxygroup
Get-SPServiceInstance | where-object {$_.TypeName -eq "Secure Store Service"} | Start-SPServiceInstance


Write-Host "Creating Visio Graphics Service and Proxy..."
New-SPVisioServiceApplication -Name $visioSAName -ApplicationPool $MainAppPoolName
New-SPVisioServiceApplicationProxy -Name "$visioSAName Proxy" -ServiceApplication $visioSAName
Get-SPServiceInstance | where-object {$_.TypeName -eq "Visio Graphics Service"} | Start-SPServiceInstance


Write-Host "Creating Web Analytics Service and Proxy..."
$stagerSubscription = "<StagingDatabases><StagingDatabase ServerName='$databaseServerName' DatabaseName='$dbNameStager'/></StagingDatabases>"
$reportingSubscription = "<ReportingDatabases><ReportingDatabase ServerName='$databaseServerName' DatabaseName='$dbNameWarehouse'/></ReportingDatabases>"
New-SPWebAnalyticsServiceApplication -Name $WebAnalyticsSAName -ApplicationPool $MainAppPoolName -ReportingDataRetention 20 -SamplingRate 100 -ListOfReportingDatabases $reportingSubscription -ListOfStagingDatabases $stagerSubscription
New-SPWebAnalyticsServiceApplicationProxy -Name "$WebAnalyticsSAName Proxy" -ServiceApplication $WebAnalyticsSAName
Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Web Service"} | Start-SPServiceInstance
Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Data Processing Service"} | Start-SPServiceInstance


Write-Host "Creating Word Conversion Service and Proxy..."
New-SPWordConversionServiceApplication -Name $WordAutomationSAName -ApplicationPool $MainAppPoolName -DatabaseServer $databaseServerName -DatabaseName $dbNameWordAutomation -Default
Get-SPServiceInstance | where-object {$_.TypeName -eq "Word Automation Services"} | Start-SPServiceInstance




#  START SEARCH

Write-Host " Creating Search Service and Proxy..."
Write-Host "   Starting Services..."
Start-SPEnterpriseSearchServiceInstance $searchServerName
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServerName

Write-Host "   Creating Search Application..."
$searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $SearchAppPoolName -DatabaseServer $databaseServerName -DatabaseName $dbNameSearch
$searchInstance = Get-SPEnterpriseSearchServiceInstance $searchServerName

Write-Host "   Creating Administration Component..."
$searchApp | Get-SPEnterpriseSearchAdministrationComponent | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstance


#  Crawl
Write-Host "   Creating Crawl Component..."
$InitialCrawlTopology = $searchApp | Get-SPEnterpriseSearchCrawlTopology -Active
$CrawlTopology = $searchApp | New-SPEnterpriseSearchCrawlTopology
$CrawlDatabase = ([array]($searchApp | Get-SPEnterpriseSearchCrawlDatabase))[0]
$CrawlComponent = New-SPEnterpriseSearchCrawlComponent -CrawlTopology $CrawlTopology -CrawlDatabase $CrawlDatabase -SearchServiceInstance $searchInstance
$CrawlTopology | Set-SPEnterpriseSearchCrawlTopology -Active

Write-Host -ForegroundColor white "   Waiting for the old crawl topology to become inactive" -NoNewline
do {write-host -NoNewline .;Start-Sleep 6;} while ($InitialCrawlTopology.State -ne "Inactive")
$InitialCrawlTopology | Remove-SPEnterpriseSearchCrawlTopology -Confirm:$false


#  Query
Write-Host "   Creating Query Component..."
$InitialQueryTopology = $searchApp | Get-SPEnterpriseSearchQueryTopology -Active
$QueryTopology = $searchApp | New-SPEnterpriseSearchQueryTopology -Partitions 1
$IndexPartition= (Get-SPEnterpriseSearchIndexPartition -QueryTopology $QueryTopology)
$QueryComponent = New-SPEnterpriseSearchQuerycomponent -QueryTopology $QueryTopology -IndexPartition $IndexPartition -SearchServiceInstance $searchInstance
$PropertyDatabase = ([array]($searchApp | Get-SPEnterpriseSearchPropertyDatabase))[0]
$IndexPartition | Set-SPEnterpriseSearchIndexPartition -PropertyDatabase $PropertyDatabase
$QueryTopology | Set-SPEnterpriseSearchQueryTopology -Active


Write-Host "   Creating Proxy..."
$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName
Write-Host "Search Complete"


# END SEARCH


Write-Host "Complete.  End of script!"

Comments

Popular posts from this blog

SharePoint Designer 2013 Approval Workflow with Comments

Change SharePoint server hostname and Web Application Names

The Timer Service Failed to Recycle