Created
March 28, 2013 02:31
-
-
Save ElliotWood/5260059 to your computer and use it in GitHub Desktop.
Build a SharePoint 2013 Farm and Provision all the service apps
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$configType = read-host "Do you wish to create a new farm? (Y/N)" | |
if ($ConfigType -eq "N") { | |
$DatabaseServer = read-host "Preparing to join existing farm. Please specify the name of your SQL Server"; | |
$ConfigDB = read-host "Next, specify the name of your Farm Configuration Database"; | |
$Passphrase = read-host "Finally, please enter your Farm passphrase" -assecurestring | |
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) { | |
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue; | |
} | |
Write-Host "Connecting to Configuration Database" | |
Connect-SPConfigurationDatabase -DatabaseName $ConfigDB -DatabaseServer $DatabaseServer -Passphrase $Passphrase | |
} else { | |
#$OWA = read-host "Have you already installed Office Web Apps? (Y/N)"; | |
#if ($OWA -eq "Y") { | |
# cd "\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\BIN" | |
# .\psconfig -cmd upgrade -inplace b2b –force -wait | |
#} | |
$DatabaseServer = read-host "Preparing to create a new Farm. Please specify the name of your SQL Server (ex SERVER or SERVER\INSTANCE[,PORT])"; | |
$FarmName = read-host "Please specify a name for your Farm (ex. SP2013), it will be used for all database prefixes."; | |
$ConfigDB = $FarmName + "_ConfigDB"; | |
$AdminContentDB = $FarmName + "_CentralAdminContent"; | |
Write-Host "Please enter the credentials for your Farm Account (ex. contoso\sp_farm)"; | |
$FarmAcct = Get-Credential; | |
$Passphrase = read-host "Enter a secure Farm passphrase (must meet password complexity requirements)" -assecurestring; | |
$Port = read-host "Enter a port number for the Central Administration Web App"; | |
$Authentication = read-host "Finally, specify your authentication provider (NTLM/Kerberos)"; | |
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) { | |
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue; | |
} | |
Write-Host "Your SharePoint Farm is being configured..." | |
#Force upgrade since OWA installed | |
#psconfig -cmd upgrade -inplace b2b -wait -force | |
Write-Host -ForegroundColor Yellow "Beginning creation of new configuration database..."; | |
New-SPConfigurationDatabase -DatabaseName $ConfigDB -DatabaseServer $DatabaseServer -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmAcct | |
} | |
Write-Host "Initialize SPResourceSecurity." | |
Initialize-SPResourceSecurity | |
Write-Host "Installing SPService." | |
Install-SPService | |
Write-Host "Installing Feature AllExistingFeatures." | |
Install-SPFeature -AllExistingFeatures | |
Write-Host "Creating Central Administration Site." | |
New-SPCentralAdministration -Port $Port -WindowsAuthProvider $Authentication | |
Write-Host "Installing HelpCollection." | |
Install-SPHelpCollection -All | |
Write-Host "Installing Application Content." | |
Install-SPApplicationContent | |
Write-Host -ForegroundColor Green "Your SharePoint 2013 Farm has been created!" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Before you run this script ensure you have the following Managed Accounts created | |
# Admin Account - Combines Farm, Admin, UserProfiles Accounts. | |
# Crawl Account | |
# Search Account | |
# Services Account | |
# Web App Pool Account | |
# | |
#################################################################################################################### | |
# Add PSSnapin | |
#################################################################################################################### | |
cls | |
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) { | |
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue; | |
#Add-PSSnapin Microsoft.SharePoint.PowerShell; | |
} | |
#################################################################################################################### | |
# Functions | |
#################################################################################################################### | |
function Start-SPService($ServiceInstanceTypeName) { | |
$ServiceInstance = (Get-SPServiceInstance | Where {$_.TypeName -eq $ServiceInstanceTypeName}) | |
if($ServiceInstance.Status -ne "Online" -and $ServiceInstance.Status -ne "Provisioning") { | |
$ServiceInstance | Start-SPServiceInstance | |
} | |
$i = 0; | |
while(-not ($ServiceInstance.Status -eq "Online") -and $i -lt 10) { | |
Write-Host -ForegroundColor Yellow "Waiting for the $ServiceInstanceTypeName service to provision..."; | |
sleep 100; | |
$ServiceInstance = (Get-SPServiceInstance | Where {$_.TypeName -eq $ServiceInstanceTypeName}) | |
$i += 1; | |
if($i -eq 10) { | |
$continue = Read-Host "Service $ServiceInstanceTypeName has not yet been provisioned. Would you like to wait? (Y/N)" | |
if($continue -eq "Y") { | |
$i = 0; | |
} | |
} | |
} | |
} | |
Function Configure-SPSearch { | |
PARAM($AppPool, $FarmName, $SearchServiceAccount) | |
$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance -local | |
Start-SPEnterpriseSearchServiceInstance -Identity $searchServiceInstance | |
$dbName = $FarmName + "_SearchServiceApplication" | |
$searchApplication = New-SPEnterpriseSearchServiceApplication -Name "$FarmName Search Service Application" -ApplicationPool $AppPool -DatabaseName $dbName | |
$searchApplicationProxy = New-SPEnterpriseSearchServiceApplicationProxy -name "$FarmName Search Service Application Proxy" -SearchApplication $searchApplication | |
# Clone the default Topology (which is empty) and create a new one and then activate it | |
Write-Host "Configuring Search Component Topology..." | |
$clone = $searchApplication.ActiveTopology.Clone() | |
$searchServiceInstance = Get-SPEnterpriseSearchServiceInstance | |
New-SPEnterpriseSearchAdminComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
New-SPEnterpriseSearchContentProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
New-SPEnterpriseSearchAnalyticsProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
New-SPEnterpriseSearchCrawlComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
New-SPEnterpriseSearchIndexComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
New-SPEnterpriseSearchQueryProcessingComponent –SearchTopology $clone -SearchServiceInstance $searchServiceInstance | |
$clone.Activate() | |
#Set-SPEnterpriseSearchAdministrationComponent -SearchApplication $searchApplication -SearchServiceInstance $searchServiceInstance | |
# | |
#$crawlTopology = New-SPEnterpriseSearchCrawlTopology -SearchApplication $searchApplication | |
#$crawlDatabase = Get-SPEnterpriseSearchCrawlDatabase -SearchApplication $searchApplication | |
# | |
#New-SPEnterpriseSearchCrawlComponent -CrawlTopology $crawlTopology -CrawlDatabase $crawlDatabase -SearchServiceInstance $searchServiceInstance | |
# | |
#while($crawlTopology.State -ne "Active") | |
#{ | |
# #In SharePoint 2010 Get-SPEnterpriseSearchCrawlTopology was used instead. | |
# $crawlTopology | New-SPEnterpriseSearchlTopology -Active -ErrorAction SilentlyContinue | |
# if ($crawlTopology.State -ne "Active") | |
# { | |
# Start-Sleep -Seconds 10 | |
# } | |
#} | |
# | |
#$queryTopology = New-SPEnterpriseSearchQueryTopology -SearchApplication $searchApplication -partitions 1 | |
#$searchIndexPartition = Get-SPEnterpriseSearchIndexPartition -QueryTopology $queryTopology | |
#New-SPEnterpriseSearchQueryComponent -indexpartition $searchIndexPartition -QueryTopology $queryTopology -SearchServiceInstance $searchServiceInstance | |
# | |
#$propertyDB = Get-SPEnterpriseSearchPropertyDatabase -SearchApplication $searchApplication | |
# | |
#Set-SPEnterpriseSearchIndexPartition $searchIndexPartition -PropertyDatabase $propertyDB | |
# | |
#while ($queryTopology.State -ne "Active") | |
#{ | |
# $queryTopology | Set-SPEnterpriseSearchQueryTopology -Active -ErrorAction SilentlyContinue | |
# | |
# if ($queryTopology.State -ne "Active") | |
# { | |
# Start-Sleep -Seconds 10 | |
# } | |
#} | |
} | |
function Start-SPTimer { | |
$spTimerService = Get-Service "SPTimerV4" | |
if($spTimerService.Status -ne "Running") { | |
Write-Host -ForegroundColor Yellow "SharePoint 2013 Timer Service is not running. Atempting to start the timer." | |
Start-Service "SPTimerV4" | |
$spTimerService = Get-Service "SPTimerV4" | |
while($spTimerService.Status -ne "Running") { | |
Start-Sleep -Seconds 10 | |
Start-Service "SPTimerV4" | |
$spTimerService = Get-Service "SPTimerV4" | |
} | |
Write-Host -ForegroundColor Green "SharePoint 2013 Timer Service is running." | |
} | |
else { | |
Write-Host -ForegroundColor Green "SharePoint 2013 Timer Service is running." | |
} | |
} | |
Function Get-SPServiceApplicationPoolByName($SPApplicationPoolName, $ManagedAccount) { | |
$appPool = Get-SPServiceApplicationPool | Where {$_.Name -eq $SPApplicationPoolName} | |
if($appPool -eq $null) { | |
$appPool = New-SPServiceApplicationPool -Name $SPApplicationPoolName -Account $ManagedAccount | |
} | |
Return $appPool | |
} | |
Function Get-SPManagedAccountByName($AccountName) { | |
$managedAccount = Get-SPManagedAccount | Where {$_.Username -eq $AccountName} | |
if($managedAccount -eq $null) { | |
Write-Host "Please enter the credentials for your Managed Account ($AccountName)"; | |
$managedAccountCredential = Get-Credential $AccountName; | |
$managedAccount = New-SPManagedAccount $managedAccountCredential | |
} | |
Return $managedAccount | |
} | |
Function Get-SPServiceApplicationByType($TypeName) { | |
$serviceApplications = Get-SPServiceApplication | Where {$_.TypeName -eq $TypeName} | |
if($serviceApplications -ne $null) { | |
$true; | |
} | |
else { | |
$false; | |
} | |
} | |
Function New-SPStateServiceApplicationGroup($FarmName){ | |
$dbName = $FarmName + "_StateService" | |
Write-Host -ForegroundColor Yellow "Installing State Service Application..." | |
New-SPStateServiceDatabase $dbName | New-SPStateServiceApplication -Name "$FarmName State Service Application" | New-SPStateServiceApplicationProxy -Name "$FarmName State Service Application Proxy" -DefaultProxyGroup | |
sleep 10; | |
Write-Host -ForegroundColor Green "State Service Application installed..." | |
} | |
Function New-SPUsageApplicationAndProxy($FarmName) { | |
Write-Host -ForegroundColor Yellow "Installing Usage and Health Data Collection Service..." | |
$dbName = $FarmName + "_UsageandHealthDataCollectionService" | |
New-SPUsageApplication "$FarmName Usage and Health Data Collection Service" -DatabaseName $dbName | |
$usageApplicationProxy = Get-SPServiceApplicationProxy | where{$_.Name -eq "$FarmName Usage and Health Data Collection Service"} | |
if($usageApplicationProxy.Status -eq "Disabled") { | |
$usageApplicationProxy.Status = "Online"; | |
$usageApplicationProxy.Update(); | |
} | |
Write-Host -ForegroundColor Green "Installing Usage and Health Data Collection Service installed." | |
} | |
# Starting SP Timer Service | |
Start-SPTimer | |
$appPoolName = Read-Host "Please specify a name for ServiceApp application pool (eg. ServiceAppPool)" | |
$dbServerName = Read-Host "Please specify the database server name (e.g. ServerName\InstanceName" | |
$managedAccountName = Read-Host "Please enter service account (eg. CompanyABC\sp_service)" | |
$managedAccount = Get-SPManagedAccountByName $managedAccountName | |
$appPool = Get-SPServiceApplicationPoolByName $appPoolName $managedAccount | |
#$DatabaseServer = read-host "Preparing to join existing farm. Please specify the name of your SQL Server"; | |
$FarmName = Read-Host "Please enter your farm name"; | |
#################################################################################################################### | |
# State Service Application | |
#################################################################################################################### | |
$decision = read-host "Would you like to install State Service Application? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
New-SPStateServiceApplicationGroup $FarmName | |
} | |
#################################################################################################################### | |
# Usage and Health Data Collection Service Application | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Usage and Health Data Collection Service Application? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
New-SPUsageApplicationAndProxy $FarmName | |
} | |
#################################################################################################################### | |
# Access Services | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Access Services? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Access Services..." | |
Start-SPService("Access Database Service") | |
New-SPAccessServiceApplication -Name "$FarmName Access Services" -ApplicationPool $appPool -Default | |
Write-Host -ForegroundColor Green "Access Services installed." | |
} | |
#################################################################################################################### | |
# Business Data Connectivity Service | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Business Data Connectivity Service? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Business Data Connectivity Service..." | |
Start-SPService("Business Data Connectivity Service") | |
$dbName = $FarmName + "_BusinessDataConnectivityService" | |
New-SPBusinessDataCatalogServiceApplication -Name "$FarmName Business Data Connectivity Service" -ApplicationPool $appPool -databaseName $dbName | |
Write-Host -ForegroundColor Green "Business Data Connectivity Service installed." | |
} | |
#################################################################################################################### | |
# Search Service | |
#################################################################################################################### | |
#check for dependency on Usage and Health and Data Collection Service | |
$decision = read-host "Would you like to install Search Service? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Search Service..." | |
$newAccount = Read-Host "Would you like to use $managedAccountName as the search service account? (Y/N)" | |
if($newAccount -eq "N") { | |
$searchAccountName = Read-Host "Please enter search account (eg. CompanyABC\sp_search)" | |
$searchAccount = Get-SPManagedAccountByName $searchAccountName | |
} | |
else { | |
$searchAccount = $managedAccount | |
} | |
if(-not (Get-SPServiceApplicationByType("Usage and Health Data Collection Service Application"))) { | |
$decision = Read-Host "Usage and Health Data Collection Service Application needs to be installed to run Search Service. Would you like to install it now (Y/N)?" | |
if ($decision -eq "Y") { | |
New-SPUsageApplicationAndProxy $FarmName | |
} | |
} | |
Write-Host -ForegroundColor Yellow "Installing Search Service." | |
Configure-SPSearch $appPoolName $FarmName $searchAccount | |
Write-Host -ForegroundColor Green "Search Service installed." | |
} | |
#################################################################################################################### | |
# Excel Services | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Excel Services? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Excel Services..." | |
Start-SPService("Excel Calculation Services") | |
New-SPExcelServiceApplication -Name "$FarmName Excel Services" -ApplicationPool $appPool -Default | |
Write-Host -ForegroundColor Green "Excel Services installed." | |
} | |
#################################################################################################################### | |
# Managed Metadata Service | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Managed Metadata Service? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Managed Metadata Service..." | |
Start-SPService("Managed Metadata Web Service") | |
$dbName = $FarmName + "_ManagedMetadataService" | |
$MetaDataServiceApp = New-SPMetadataServiceApplication -Name "$FarmName Managed Metadata Service" -ApplicationPool $appPool -DatabaseName $dbName | |
$MetaDataServiceAppProxy = New-SPMetadataServiceApplicationProxy -Name "$FarmName Managed Metadata Service Proxy" -ServiceApplication $MetaDataServiceApp -DefaultProxyGroup | |
Write-Host -ForegroundColor Green "Managed Metadata Service installed." | |
} | |
#################################################################################################################### | |
# Secure Store Service | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Secure Store Service? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Secure Store Service..." | |
Start-SPService("Secure Store Service") | |
$dbName = $FarmName + "_SecureStore" | |
$secureStoreServiceApp = New-SPSecureStoreServiceApplication -Name "$FarmName Secure Store Service Application" -ApplicationPool $appPool -DatabaseName $dbName -AuditingEnabled:$true | |
New-SPSecureStoreServiceApplicationProxy -ServiceApplication $secureStoreServiceApp -Name "$FarmName Secure Store Service Application Proxy" -DefaultProxyGroup | |
Write-Host -ForegroundColor Green "Secure Store Service installed." | |
} | |
#################################################################################################################### | |
# Visio Graphics Service | |
#################################################################################################################### | |
#check for dependency on State Service | |
$decision = read-host "Would you like to install Visio Graphics Service? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Visio Graphics Service..." | |
Start-SPService("Visio Graphics Service") | |
New-SPVisioServiceApplication -Name "$FarmName Visio Graphics Service" -ApplicationPool $appPool | |
New-SPVisioServiceApplicationProxy -Name "$FarmName Visio Graphics Service Proxy" -ServiceApplication "$FarmName Visio Graphics Service" | |
Write-Host -ForegroundColor Green "Visio Graphics Service installed." | |
} | |
#################################################################################################################### | |
# Word Automation Services | |
#################################################################################################################### | |
$decision = read-host "Would you like to install Word Automation Services? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing Word Automation Services..." | |
Start-SPService("Word Automation Services") | |
$dbName = $FarmName + "_WordAutomationServices" | |
New-SPWordConversionServiceApplication -Name "$FarmName Word Automation Services" -ApplicationPool $appPool -DatabaseName $dbName -Default | |
Write-Host -ForegroundColor Green "Word Automation Services installed." | |
} | |
#################################################################################################################### | |
# PerformancePoint Services | |
#################################################################################################################### | |
#check for dependency on Excel Services and State Service | |
$decision = read-host "Would you like to install PerformancePoint Services? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing PerformancePoint Services..." | |
Start-SPService("PerformancePoint Service") | |
$dbName = $FarmName + "_PerformancePointService" | |
New-SPPerformancePointServiceApplication -Name "$FarmName PerformancePoint Service" -ApplicationPool $appPool -DatabaseName $dbName | |
New-SPPerformancePointServiceApplicationProxy -Name "$FarmName PerformancePoint Service Proxy" -ServiceApplication "$FarmName PerformancePoint Service" -Default | |
Write-Host -ForegroundColor Green "PerformancePoint Service installed." | |
} | |
#################################################################################################################### | |
# User Profile Service | |
#################################################################################################################### | |
$decision = read-host "Would you like to install User Profile Service? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Installing User Profile Service..." | |
Start-SPService("User Profile Service") | |
$profileDB = $FarmName + "_UserProfileService_Profile_DB" | |
$syncDB = $FarmName + "_UserProfileService_Sync_DB" | |
$socialDB = $FarmName + "_UserProfileService_Social_DB" | |
$ups = New-SPProfileServiceApplication -Name "$FarmName User Profile Service" -ApplicationPool $appPool -ProfileDBName $profileDB -ProfileSyncDBName $syncDB -SocialDBName $socialDB | |
New-SPProfileServiceApplicationProxy -Name "$FarmName User Profile Service Proxy" -ServiceApplication $ups -DefaultProxyGroup | |
Write-Host -ForegroundColor Green "User Profile Service installed." | |
} | |
$decision = read-host "Would you like to create a Web Application? (Y/N) Recommended" | |
if ($decision -eq "Y") { | |
#TODO: Add code for creating new web application | |
$webAppAccountName = Read-Host "Please enter Web Application's App Pool account (eg. CompanyABC\sp_search)" | |
$webAppAccount = Get-SPManagedAccountByName $webAppAccountName | |
Get-SPManagedAccountByName($webAppAccount) | |
} | |
#################################################################################################################### | |
# Web Analytics Service..DOESNT EXIST IN SP2013 | |
#################################################################################################################### | |
#check for dependency on State Service | |
#$decision = read-host "Would you like to install Web Analytics Services? (Y/N) Recommended" | |
#if ($decision -eq "Y") { | |
# Write-Host -ForegroundColor Yellow "Installing Web Analytics Service..." | |
# Start-SPService("Web Analytics Data Processing Service") | |
# Start-SPService("Web Analytics Web Service") | |
# | |
# $ServiceName = "$FarmName Web Analytics Service" | |
# $stagingDB = $FarmName + "_WebAnalytics_Staging_DB" | |
# $reportingDB = $FarmName + "_WebAnalytics_Reporting_DB" | |
# $reportingDBList = "<ReportingDatabases><ReportingDatabase ServerName='$dbServerName' DatabaseName='$reportingDB'/></ReportingDatabases>" | |
# $stagingDBList = "<StagingDatabases><StagingDatabase ServerName='$dbServerName' DatabaseName='$stagingDB'/></StagingDatabases>" | |
# | |
# New-SPWebAnalyticsServiceApplication -Name $ServiceName -ApplicationPool $appPool -ListOfReportingDatabases $reportingDBList -ListOfStagingDatabases $stagingDBList | |
# New-SPWebAnalyticsServiceApplicationProxy -Name "$ServiceName Proxy" -ServiceApplication $ServiceName | |
# | |
# Write-Host -ForegroundColor Green "Web Analytics Service installed." | |
#} | |
#################################################################################################################### | |
# Microsoft SharePoint Foundation Sandboxed Code Service | |
#################################################################################################################### | |
$decision = read-host "Would you like to start Microsoft SharePoint Foundation Sandboxed Code Service? (Y/N) Not Recommended" | |
if ($decision -eq "Y") { | |
Write-Host -ForegroundColor Yellow "Configuring Microsoft SharePoint Foundation Sandboxed Code Service..." | |
Start-SPService("Microsoft SharePoint Foundation Sandboxed Code Service") | |
Write-Host -ForegroundColor Green "Microsoft SharePoint Foundation Sandboxed Code Service configured." | |
} | |
iisreset | |
Write-Host -ForegroundColor Green "Installation completed." | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment