Configure a service application by using a Windows PowerShell script (SharePoint Server 2010)
Applies to: SharePoint Server 2010, SharePoint Foundation 2010
This article describes how a user can use a Windows PowerShell script to replicate the functionality of the SharePoint Products Configuration Wizard in Microsoft SharePoint Server 2010.
Note
The following Windows PowerShell script replicates the majority of the functionality of the SharePoint Products Configuration Wizard with the exception of the Application Registry service and the Lotus Notes connector. To configure both of these services, see Application Registry Service administration (SharePoint Server 2010) and Configure and use the Lotus Notes connector (SharePoint Server 2010) respectively.
To create and configure the farm, you run the SharePoint Products Configuration Wizard. This wizard automates several configuration tasks, including creating the configuration database, installing services, creating service application and service application proxies, and creating the Central Administration Web site.
For additional information about deploying a farm, see Multiple servers for a three-tier farm (SharePoint Server 2010).
One of the limitations of using the SharePoint Products Configuration Wizard is in order to provision the services in the farm, all of the steps must be performed consecutively until the SharePoint Products Configuration Wizard is complete. Alternatively, by using the following Windows PowerShell script, an administrator can be selective in what services are run by copying and pasting the appropriate code into a separate .ps1 file.
Some of the services are dependent on each other to run, so both must appear in your version of the script. For example, to use Web Analytics reporting, the Web Analytics service requires the State service to be started. The following table shows services and their dependencies.
Service name | Dependent service |
---|---|
Access Service |
None |
Business Data Connectivity service |
None |
Excel Services Application |
None |
Managed Metadata Web service |
None |
PerformancePoint Service |
Excel Services State Service |
SharePoint Server Search |
Usage and Health Data Collection Service |
State Service |
None |
Secure Store Service |
None |
Usage and Health Data Collection Service |
None |
User Profile Synchronization Service |
None |
Visio Graphics service |
State Service |
Web Analytics service |
State Service |
Word Automation Services |
None |
To configure a service application by using a Windows PowerShell script
Verify that you meet the following minimum requirements:
See Add-SPShellAdmin.
You must read about_Execution_Policies (https://go.microsoft.com/fwlink/p/?LinkId=193050).
Copy the following code and paste it into a text editor, such as Notepad.
Note
The $appPoolUserName uses a sample account, CONTOSO\SAAppPoolAccount, which needs to be changed to a valid account within your organization.
################################################################################ ## This script replicates most of the functionality found in the SharePoint Products Configuration Wizard## ################################################################################ Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue ## Settings you may want to change ## $databaseServerName = "sp2010dev.contoso.com" $searchServerName = $databaseServerName $saAppPoolName = "SharePoint Web Services" $appPoolUserName = "CONTOSO\SAAppPoolAccount" ## Service Application Service Names ## $accesssSAName = "Access 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" $userProfileSAName = "User Profile Synchronization Service" $visioSAName = "Visio Graphics Service" $WebAnalyticsSAName = "Web Analytics Service" $WordAutomationSAName = "Word Automation Services" $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 "MetadataDB" > $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 > $null New-SPPerformancePointServiceApplicationProxy -Default -Name "$performancePointSAName Proxy" -ServiceApplication $performancePointSAName > $null Get-SPServiceInstance | where-object {$_.TypeName -eq "PerformancePoint Service"} | Start-SPServiceInstance > $null ##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 $saAppPoolName -DatabaseServer $databaseServerName -DatabaseName "SearchDB" $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 Write-Host ##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 > $null #####END SEARCH Write-Host "Creating State Service and Proxy..." New-SPStateServiceDatabase -Name "StateServiceDB" -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 User Profile Service and Proxy..." $userProfileService = New-SPProfileServiceApplication -Name $userProfileSAName -ApplicationPool $saAppPoolName -ProfileDBServer $databaseServerName -ProfileDBName "ProfileDB" -SocialDBServer $databaseServerName -SocialDBName "SocialDB" -ProfileSyncDBServer $databaseServerName -ProfileSyncDBName "SyncDB" New-SPProfileServiceApplicationProxy -Name "$userProfileSAName Proxy" -ServiceApplication $userProfileService -DefaultProxyGroup > $null Get-SPServiceInstance | where-object {$_.TypeName -eq "User Profile 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 Web Analytics Service and Proxy..." $stagerSubscription = "<StagingDatabases><StagingDatabase ServerName='$databaseServerName' DatabaseName='StagerDB'/></StagingDatabases>" $reportingSubscription = "<ReportingDatabases><ReportingDatabase ServerName='$databaseServerName' DatabaseName='WarehouseDB'/></ReportingDatabases>" New-SPWebAnalyticsServiceApplication -Name $WebAnalyticsSAName -ApplicationPool $saAppPoolName -ReportingDataRetention 20 -SamplingRate 100 -ListOfReportingDatabases $reportingSubscription -ListOfStagingDatabases $stagerSubscription > $null New-SPWebAnalyticsServiceApplicationProxy -Name "$WebAnalyticsSAName Proxy" -ServiceApplication $WebAnalyticsSAName > $null Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Web Service"} | Start-SPServiceInstance > $null Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Data Processing 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
Save the file, naming it
Services.ps1
.Note
You can use a different file name, but you must save the file as an ANSI-encoded text file whose extension is .ps1.
On the Start menu, click All Programs.
Click Microsoft SharePoint 2010 Products.
Click SharePoint 2010 Management Shell.
Change to the directory where you saved the file.
At the Windows PowerShell command prompt, type the following command:
./Services.ps1
For additional information about Windows PowerShell scripts and .ps1 files, see Running Windows PowerShell Scripts.