#Load Modules
Import-Module WebAdministration
#Get the current location
[string]$curloc = get-location
$ScriptVarsxml = [xml](get-content "$curloc\ScriptVars.xml" -EA 0)
if ($ScriptVarsxml -eq $null)
{
[xml]$ScriptVarsxml = '
'
#Region Get Input Variables
function UpdateVarsxml
{
param([string]$Name,[string]$Value)
$newNode = $ScriptVarsxml.CreateElement("Variable")
$newNode.SetAttribute("Name","$Name")
$newNode.SetAttribute("Value","$Value")
$ScriptVarsxml["Variables"].AppendChild($newNode)
}
#Choose the edition of SharePoint 2010 you are installing
Write-Host -ForegroundColor Blue "Choose your version."
Write-Host -ForegroundColor Blue "1. Foundation"
Write-Host -ForegroundColor Blue "2. SearchServer"
Write-Host -ForegroundColor Blue "3. Standard"
Write-Host -ForegroundColor Blue "4. Standard + Internet"
Write-Host -ForegroundColor Blue "5. Enterprise"
Write-Host -ForegroundColor Blue "6. Enterprise + Internet"
Write-Host -ForegroundColor Blue " "
$Edition = Read-Host "Select 1-6: "
UpdateVarsxml "Edition" $Edition > $null
$isCA = Read-Host "Is this server the Central Admin (Y or N - blank/default=No) "
UpdateVarsxml "IsCA" $isCA > $null
$DBServer = Read-Host "Database Server (default=$env:COMPUTERNAME) "
#Set $DBServer to local server name if it wasn;t specified
if($DBServer -eq ""){$DBServer = "$env:COMPUTERNAME"}
UpdateVarsxml "DBServer" $DBServer > $null
#$searchServer = Read-Host "Search Server (default=$env:COMPUTERNAME) "
$FarmPrefix = Read-Host "Enter a Prefix for the Database Names (ex. Dev or Prod or Leave Blank if Customer only has one Farm) "
UpdateVarsxml "FarmPrefix" $FarmPrefix > $null
#Site Variables
$PortalName = Read-Host "Enter the name of the first Web Application "
UpdateVarsxml "PortalName" $PortalName > $null
$PortalHostHeader = Read-Host "Enter the Host Header "
UpdateVarsxml "PortalHostHeader" $PortalHostHeader > $null
$PortalPort = Read-Host "Enter the Port "
UpdateVarsxml "PortalPort" $PortalPort > $null
$PUseSSL = Read-Host "Use SSL? (Y or N - blank/default=No) "
if ($PUseSSL -eq "Y" -or $PUseSSL -eq "y")
{
$PortalUseSSL = $true
UpdateVarsxml "PortalUseSSL" $PortalUseSSL > $null
$PortalPrefix = "https://"
UpdateVarsxml "PortalPrefix" $PortalPrefix > $null
}
else{$PortalUseSSL = $false;UpdateVarsxml "PortalUseSSL" $PortalUseSSL > $null;$PortalPrefix = "http://";UpdateVarsxml "PortalPrefix" $PortalPrefix > $null}
$PortalLCID = "1033"
UpdateVarsxml "PortalLCID" $PortalLCID > $null
#List Template Names
"Name Title
---- -----
GLOBAL#0 Global template
STS#0 Team Site
STS#1 Blank Site
STS#2 Document Workspace
MPS#0 Basic Meeting Workspace
MPS#1 Blank Meeting Workspace
MPS#2 Decision Meeting Workspace
MPS#3 Social Meeting Workspace
MPS#4 Multipage Meeting Workspace
CENTRALADMIN#0 Central Admin Site
WIKI#0 Wiki Site
BLOG#0 Blog
SGS#0 Group Work Site
TENANTADMIN#0 Tenant Admin Site
ACCSRV#0 Access Services Site
ACCSRV#1 Assets Web Database
ACCSRV#3 Charitable Contributions Web Database
ACCSRV#4 Contacts Web Database
ACCSRV#6 Issues Web Database
ACCSRV#5 Projects Web Database
BDR#0 Document Center
OFFILE#0 (obsolete) Records Center
OFFILE#1 Records Center
OSRV#0 Shared Services Administration Site
PPSMASite#0 PerformancePoint
BICenterSite#0 Business Intelligence Center
SPS#0 SharePoint Portal Server Site
SPSPERS#0 SharePoint Portal Server Personal Space
SPSMSITE#0 Personalization Site
SPSTOC#0 Contents area Template
SPSTOPIC#0 Topic area template
SPSNEWS#0 News Site
CMSPUBLISHING#0 Publishing Site
BLANKINTERNET#0 Publishing Site
BLANKINTERNET#1 Press Releases Site
BLANKINTERNET#2 Publishing Site with Workflow
SPSNHOME#0 News Site
SPSSITES#0 Site Directory
SPSCOMMU#0 Community area template
SPSREPORTCENTER#0 Report Center
SPSPORTAL#0 Collaboration Portal
SRCHCEN#0 Enterprise Search Center
PROFILES#0 Profiles
BLANKINTERNETCONTAINER#0 Publishing Portal
SPSMSITEHOST#0 My Site Host
ENTERWIKI#0 Enterprise Wiki
SRCHCENTERLITE#0 Basic Search Center
SRCHCENTERLITE#1 Basic Search Center
SRCHCENTERFAST#0 FAST Search Center
visprus#0 Visio Process Repository"
$PortalTemplate = Read-Host "Enter the Template Name"
UpdateVarsxml "PortalTemplate" $PortalTemplate > $null
$MySiteName = "MySites"
UpdateVarsxml "MySiteName" $MySiteName > $null
$MySiteHostHeader = Read-Host "Enter the Host Header for the MySites App "
UpdateVarsxml "MySiteHostHeader" $MySiteHostHeader > $null
$MySitePort = Read-Host "Enter the Port "
UpdateVarsxml "MySitePort" $MySitePort > $null
$MUseSSL = Read-Host "Use SSL? (Y or N - blank/default=No) "
if ($MUseSSL -eq "Y" -or $MUseSSL -eq "y")
{
$MySiteUseSSL = $true
UpdateVarsxml "MySiteUseSSL" $MySiteUseSSL > $null
$MySitePrefix = "https://"
UpdateVarsxml "MySitePrefix" $MySitePrefix > $null
}
else{$MySiteUseSSL = $false;UpdateVarsxml "MySiteUseSSL" $MySiteUseSSL > $null;$MySitePrefix = "http://";UpdateVarsxml "MySitePrefix" $MySitePrefix > $null}
$MySiteLCID = "1033"
UpdateVarsxml "MySiteLCID" $MySiteLCID > $null
$MySiteTemplate = "SPSMSITEHOST#0"
UpdateVarsxml "MySiteTemplate" $MySiteTemplate > $null
#End Region Get Input Variables
$ScriptVarsxml.Save("$curloc\ScriptVars.xml")
}
else
{
function ReadXMLVars
{
param([string]$Name)
$ReadVar = $ScriptVarsxml.selectSingleNode("//Variables/Variable[@Name='$Name']")
$ReadVar.Value
}
$Edition = ReadXMLVars "Edition"
$IsCA = ReadXMLVars "IsCA"
$DBServer = ReadXMLVars "DBServer"
$FarmPrefix = ReadXMLVars "FarmPrefix"
$PortalName = ReadXMLVars "PortalName"
$PortalHostHeader = ReadXMLVars "PortalHostHeader"
$PortalPort = ReadXMLVars "PortalPort"
$PortalUseSSL = ReadXMLVars "PortalUseSSL"
if ($PortalUseSSL -eq "True")
{
$PortalUseSSL = $true
}
else
{
$PortalUseSSL = $false
}
$PortalPrefix = ReadXMLVars "PortalPrefix"
$PortalLCID = ReadXMLVars "PortalLCID"
$PortalTemplate = ReadXMLVars "PortalTemplate"
$MySiteName = ReadXMLVars "MySiteName"
$MySiteHostHeader = ReadXMLVars "MySiteHostHeader"
$MySitePort = ReadXMLVars "MySitePort"
$MySiteUseSSL = ReadXMLVars "MySiteUseSSL"
if ($MySiteUseSSL -eq "True")
{
$MySiteUseSSL = $true
}
else
{
$MySiteUseSSL = $false
}
$MySitePrefix = ReadXMLVars "MySitePrefix"
$MySiteLCID = ReadXMLVars "1033"
$MySiteTemplate = ReadXMLVars "MySiteTemplate"
}
#Region Build Common Variables
#Set the Service Account Prefix
if ($FarmPrefix -eq "")
{
$AcctPrefix = ""
}
else
{
$AcctPrefix = $FarmPrefix + "_"
$FarmPrefix = $FarmPrefix + "_"
}
$PortalDB = $FarmPrefix + "SP2010_" + $PortalName + "_Content"
$PortalAppPool = "SharePoint - " + $FarmPrefix + $PortalName
$PortalURL = $PortalPrefix + $PortalHostHeader
$MySiteDB = $FarmPrefix + "SP2010_" + $MySiteName + "_Content"
$MySiteAppPool = $PortalAppPool
$MySiteURL = $MySitePrefix + $MySiteHostHeader
#Build Service App Variables
$CreateBCSServiceApp = "1"
if ($Edition -gt 1)
{
$StartSearchQueryAndSiteSettingsService = "1"
$StartEnterpriseSearch = "1"
}
if ($Edition -gt 2)
{
$CreateSecureStoreServiceApp = "1"
$CreateMetadataServiceApp = "1"
$CreateWSSUsageApp = "1"
$CreateWebAnalytics = "1"
$CreateStateServiceApp = "1"
$CreateUserProfileApp = "1"
$StartSandboxedCodeService = "1"
}
if ($Edition -gt 4)
{
$CreateExcelApp = "1"
$CreateAccessApp = "1"
$CreateWordApp = "1"
$CreateVisioApp = "1"
$CreatePerformancePoint = "1"
}
Switch ($Edition)
{
3 {$ProductKey = "W7VJD-Q9KJR-GMVTH-HGM2M-CQ67V"}
4 {$ProductKey = "KC9PV-HV9HV-GBMPQ-VDCQV-KYDV7"}
5 {$ProductKey = "C63K8-P47HD-JM443-K2VP6-Y3FFQ"}
6 {$ProductKey = "C883Q-B787C-6YF2Y-V76DX-VP9DC"}
}
# Open/Create the Users.txt file
$text = "$curloc\ServiceAccounts.txt"
#Get Current Date
$date = Get-Date
#Set Farm Account Names (In case we need to change it for custom installs)
$FarmAcct = $AcctPrefix + "SP_Connect"
$FarmAdmin = $AcctPrefix + "SP_Admin"
$ServiceAppAP = $AcctPrefix + "SP_SAAppPool"
$SiteAP = $AcctPrefix + "SP_SiteAppPool"
$SiteAdmin = $AcctPrefix + "Site_Admin"
$UserProfileSynch = $AcctPrefix + "SP_UPS"
$bits = Get-Item $curloc | Split-Path -Parent
$ConfigFile = "config.xml"
$ConfigDB = $FarmPrefix + "SharePoint_Config"
$CentralAdminContentDB = $FarmPrefix + "SharePoint_AdminContent"
$FarmPassPhrase = "R@ckSp@ce!sK!ng"
$SecPhrase = ConvertTo-SecureString "$FarmPassPhrase" -asplaintext -force
$CentralAdminPort = "5000"
#Service App 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"
#DB Names
$BCSDB = $FarmPrefix + "BusinessDataCatalogDB"
$MetaDataDB = $FarmPrefix + "MetadataDB"
$SecureStoreDB = $FarmPrefix + "SecureStoreServiceAppDB"
$SearchDB = $FarmPrefix + "SearchDB"
$ProfileDB = $FarmPrefix + "ProfileDB"
$StateServiceDB = $FarmPrefix + "StateServiceDB"
$SyncDB = $FarmPrefix + "SyncDB"
$SocialDB = $FarmPrefix + "SocialDB"
$WSSUsageDB = $FarmPrefix + "UsageDB"
$StagerDB = $FarmPrefix + "StagerDB"
$WHouseDB = $FarmPrefix + "WarehouseDB"
$WordAutomationDB = $FarmPrefix + "WordAutomationDB"
#End Region Build Common Variables
#Region Global Functions
#Function Pause Script
function Pause
{
#From http://www.microsoft.com/technet/scriptcenter/resources/pstips/jan08/pstip0118.mspx
Write-Host -ForegroundColor Blue "Press any key to exit..."
$null = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
#Function Get NetBios Name for current AD
function GetDomainNetBios
{
$a = "LDAP://CN=Partitions," + ([ADSI]'LDAP://RootDSE').configurationNamingContext
$b = [ADSI] $a
foreach($index in $b.children)
{
$e = [ADSI] $index.path
if ($e.nCName -eq ([ADSI]'LDAP://RootDSE').defaultNamingContext)
{
$e.nETBIOSName
}
}
}
#End Region Global Functions
#Region Create AD Service Accounts
#Get AD Information
#Connect to current domain
$dom = [System.DirectoryServices.ActiveDirectory.Domain]::getcurrentdomain()
#Construct a valid UPN
$UPN = "@" + $dom.Name
#Construct connection strings to AD
$rootDSE = [ADSI]'LDAP://RootDSE'
$strdomain = "LDAP://OU=SharePoint,OU=Service Accounts," + $rootDSE.defaultNamingContext
$domain = [ADSI]$strdomain
$netBios = GetDomainNetBios
$domFarmAcct = "$netbios\$FarmAcct"
$domFarmAdmin = "$netbios\$FarmAdmin"
$domServiceAppAP = "$netbios\$ServiceAppAP"
$domSiteAP = "$netbios\$SiteAP"
$domSiteAdmin = "$netbios\$SiteAdmin"
$domUserProfileSynch = "$netbios\$UserProfileSynch"
$ServiceAccountsxml = [xml](get-content "$curloc\ServiceAccounts.xml" -EA 0)
if ($ServiceAccountsxml -eq $null)
{
# Build the ServiceAccounts.xml template
[xml]$ServiceAccountsxml = '
'
#Initiate the Service Account Creation Log
"Service Account Creation Log - $date" | out-file "$text"
"" | out-file "$text" -append
$arAccountNames = $FarmAcct,$FarmAdmin,$ServiceAppAP,$SiteAP,$SiteAdmin,$UserProfileSynch
$arAccountPassList = @()
#Check to see if the Service Accounts OU already exists
$rootAD = New-Object System.DirectoryServices.DirectoryEntry
$search = [System.DirectoryServices.DirectorySearcher]$rootAD
$search.Filter = "(&(name=Service Accounts)(objectCategory=organizationalunit))"
$OUSAExists = $search.FindOne()
#If the Service Accounts OU exists, Check for the SharePoint OU
if ($OUSAExists -ne $null)
{
$strSAOU = "LDAP://OU=Service Accounts," + $rootDSE.defaultNamingContext
$SAOU = [ADSI]$strSAOU
#Check to see if the SharePoint OU already exists
$search = [System.DirectoryServices.DirectorySearcher]$rootAD
$search.Filter = "(&(name=SharePoint)(objectCategory=organizationalunit))"
$OUSPExists = $search.FindOne()
#If the SharePoint OU does not exist, Create it
if ($OUSPExists -eq $null)
{
$ou = $SAOU.Create("organizationalunit", "ou=SharePoint")
$ou.SetInfo()
}
}
#Otherwise create both the Service Accounts and SharePoint OUs
else
{
$ou = $rootAD.Create("organizationalunit", "ou=Service Accounts")
$ou.SetInfo()
$strSAOU = "LDAP://OU=Service Accounts," + $rootDSE.defaultNamingContext
$SAOU = [ADSI]$strSAOU
$ou = $SAOU.Create("organizationalunit", "ou=SharePoint")
$ou.SetInfo()
}
#Generate a new random password
function Get-RandomPassword {
param($length = 10,$characters = 'abcdefghkmnprstuvwxyzABCDEFGHKLMNPRSTUVWXYZ123456789!"§$%&/()=?*+#_')
# select random characters
$random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
# output random pwd
$private:ofs=""
[String]$characters[$random]
}
function Randomize-Text {
param($text)
$anzahl = $text.length -1
$indizes = Get-Random -InputObject (0..$anzahl) -Count $anzahl
$private:ofs=''
[String]$text[$indizes]
}
function Get-ComplexPassword {
$password = Get-RandomPassword -length 3 -characters 'abcdefghiklmnprstuvwxyz'
#$password += Get-RandomPassword -length 2 -characters '#*+)'
$password += Get-RandomPassword -length 3 -characters '123456789'
$password += Get-RandomPassword -length 3 -characters 'ABCDEFGHKLMNPRSTUVWXYZ'
Randomize-Text $password
}
#Process each account name in the $arAccountNames array
foreach ($AccountName in $arAccountNames)
{
#Check to see if the user already exists
$search = [System.DirectoryServices.DirectorySearcher]$rootAD
$search.Filter = "(sAMAccountName=$AccountName)"
$UserExists = $search.FindAll()
#If the user exists do nothing otherwise create the new user account
if($UserExists -ne $null)
{
$Password = Read-Host "User Already Exists! Please enter Password for $AccountName "
$userPass = $AccountName + " " + $Password
$userPass | out-file "$text" -append
$newNode = $ServiceAccountsxml.CreateElement("ServiceAccount")
$newNode.SetAttribute("Name","$netBios\$AccountName")
$newNode.SetAttribute("Password",$Password)
$ServiceAccountsxml["ServiceAccounts"].AppendChild($newNode)
}
else
{
$Password = Get-ComplexPassword
#Generate UserName and Password combo for logging
$AccountPass = $netBios + "\" + $AccountName + " " + $Password
# User Creation
$newuser = $domain.create("user","cn=" + $AccountName)
$newuser.setinfo()
$newuser.samaccountname = $AccountName
$newuser.setinfo()
$newuser.givenname = $AccountName
$newuser.displayname = $AccountName
$newuser.userprincipalname = $AccountName + $UPN
$newuser.setinfo()
$newuser.SetPassword($Password)
$newuser.setinfo()
$newuser.userAccountControl = 66048
$newuser.setinfo()
$userPass = $AccountName + " " + $Password
$userPass | out-file "$text" -append
$newNode = $ServiceAccountsxml.CreateElement("ServiceAccount")
$newNode.SetAttribute("Name","$netBios\$AccountName")
$newNode.SetAttribute("Password",$Password)
$ServiceAccountsxml["ServiceAccounts"].AppendChild($newNode)
}
#Reset the $UserExists variable
$UserExists = ""
}
$ServiceAccountsxml.Save("$curloc\ServiceAccounts.xml")
}
#End Region Create AD Service Accounts
#Region Configure Pre-Requisites
#Check SQL Access for Current User
Function CheckSQLAccess
{
Write-Host -ForegroundColor Blue "- Checking access to SQL server (or instance) `"$DBServer`"..."
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlConnection.ConnectionString = "Server=$DBServer;Database=master;Integrated Security=True"
$SqlCmd.CommandText = "SELECT HAS_DBACCESS('master')"
$SqlCmd.Connection = $SqlConnection
$SqlCmd.CommandTimeout = 10
Try
{
$SqlCmd.Connection.Open()
$SqlCmd.ExecuteReader() | Out-Null
}
Catch
{
Write-Error $_
Write-Warning " - Connection failed to SQL server or instance `"$DBServer`"!"
Write-Warning " - Check the server (or instance) name, or verify rights for the Current Logged on User."
$SqlCmd.Connection.Close()
Pause
break
}
Write-Host -ForegroundColor Blue " - Current Logged On User appears to have access."
$SqlCmd.Connection.Close()
}
CheckSQLAccess
#Get OS Version
$QueryOS = Gwmi Win32_OperatingSystem
$QueryOS = $QueryOS.Version
If ($QueryOS.contains("6.1")) {$OS = "Win2008R2"}
ElseIf ($QueryOS.contains("6.0")) {$OS = "Win2008"}
Write-Host -ForegroundColor Blue "- Running on $OS."
#Disable Loopback Check
$LsaPath = "HKLM:\System\CurrentControlSet\Control\Lsa"
$LsaPathValue = Get-ItemProperty -path $LsaPath
If (-not ($LsaPathValue.DisableLoopbackCheck -eq "1"))
{
New-ItemProperty HKLM:\System\CurrentControlSet\Control\Lsa -Name "DisableLoopbackCheck" -value "1" -PropertyType dword -Force | Out-Null
}
#Add SP_Connect (Farm Account) as a local admin temporarily
Write-Host -ForegroundColor Blue "- Adding $domFarmAcct to local Administrators (for User Profile Sync)..."
try
{
([ADSI]"WinNT://$env:COMPUTERNAME/Administrators,group").Add("WinNT://$netBios/$FarmAcct")
If (-not $?) {throw}
}
catch {Write-Host -ForegroundColor Blue " - $domFarmAcct is already an Administrator, continuing."}
#Install Pre-requisites
Write-Host -ForegroundColor Blue "- Installing SharePoint Pre-Requisites..."
If (Test-Path "$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\14\BIN\stsadm.exe") #Crude way of checking if SP2010 is already installed
{
Write-Host -ForegroundColor Blue "- SP2010 prerequisites appear be already installed - skipping installation."
}
Else
{
Try
{
Start-Process "$bits\PrerequisiteInstaller.exe" -Wait -ArgumentList "/unattended" -WindowStyle Minimized
If (-not $?) {throw}
}
catch
{
Write-Host -ForegroundColor Red "- Error: $LastExitCode"
If ($LastExitCode -eq "1") {throw "- Another instance of this application is already running"}
ElseIf ($LastExitCode -eq "2") {throw "- Invalid command line parameter(s)"}
ElseIf ($LastExitCode -eq "1001") {throw "- A pending restart blocks installation"}
ElseIf ($LastExitCode -eq "3010") {throw "- A restart is needed"}
Else {throw "- An unknown error occurred installing prerequisites"}
}
## Parsing most recent PreRequisiteInstaller log for errors or restart requirements, since $LastExitCode doesn't seem to work...
$PreReqLog = get-childitem $env:TEMP | ? {$_.Name -like "PrerequisiteInstaller.*"} | Sort-Object -Descending -Property "LastWriteTime" | Select-Object -first 1
If ($PreReqLog -eq $null)
{
Write-Warning " - Could not find PrerequisiteInstaller log file"
}
Else
{
## Get error(s) from log
$PreReqLastError = $PreReqLog | select-string -SimpleMatch -Pattern "Error" -Encoding Unicode | ? {$_.Line -notlike "*Startup task*"}
If ($PreReqLastError)
{
Write-Warning $PreReqLastError.Line
$PreReqLastReturncode = $PreReqLog | select-string -SimpleMatch -Pattern "Last return code" -Encoding Unicode | Select-Object -Last 1
If ($PreReqLastReturnCode) {Write-Warning $PreReqLastReturncode.Line}
Write-Host -ForegroundColor Blue " - Review the log file and try to correct any error conditions."
Pause
Invoke-Item $env:TEMP\$PreReqLog
break
}
## Look for restart requirement in log
$PreReqRestartNeeded = $PreReqLog | select-string -SimpleMatch -Pattern "0XBC2=3010" -Encoding Unicode
If ($PreReqRestartNeeded)
{
Write-Warning " - One or more of the prerequisites requires a restart."
Write-Host -ForegroundColor Blue " - Run the script again after restarting to continue."
Pause
break
}
}
Write-Progress -Activity "Installing Prerequisite Software" -Status "Done." -Completed
Write-Host -ForegroundColor Blue "- All Prerequisite Software installed successfully."
}
#End Region Configure Pre-Requisites
#Region Install SharePoint Bits
$configxml = [xml](get-content "$curloc\$ConfigFile")
$PKeyNode=$configxml.selectSingleNode("//Configuration/PIDKEY")
$PKeyNode.SetAttribute('Value',$ProductKey)
$configxml.Save("$curloc\$ConfigFile")
$FarmAcctNode = $ServiceAccountsxml.selectSingleNode("//ServiceAccounts/ServiceAccount[@Name='$domFarmAcct']")
$txtFarmAcctPWD = $FarmAcctNode.Password
$FarmAcctPWD = ConvertTo-SecureString "$txtFarmAcctPWD" -asplaintext -force
$Cred_Farm = New-Object System.Management.Automation.PsCredential $domFarmAcct,$FarmAcctPWD
Function InstallSharePoint
{
If (Test-Path "$env:CommonProgramFiles\Microsoft Shared\Web Server Extensions\14\BIN\stsadm.exe") #Crude way of checking if SP2010 is already installed
{
Write-Host -ForegroundColor Blue "- SP2010 binaries appear to be already installed - skipping installation."
}
Else
{
## Install SharePoint Binaries
If (Test-Path "$bits\setup.exe")
{
Write-Host -ForegroundColor Blue "- Installing SharePoint binaries..."
try
{
Start-Process "$bits\setup.exe" -ArgumentList "/config `"$curloc\$ConfigFile`"" -WindowStyle Minimized -Wait
If (-not $?) {throw}
}
catch
{
Write-Warning "- Error $LastExitCode occurred running $bits\setup.exe"
break
}
## Parsing most recent SharePoint Server Setup log for errors or restart requirements, since $LastExitCode doesn't seem to work...
$SetupLog = get-childitem $env:TEMP | ? {$_.Name -like "SharePoint Server Setup*"} | Sort-Object -Descending -Property "LastWriteTime" | Select-Object -first 1
If ($SetupLog -eq $null)
{
Write-Warning " - Could not find SharePoint Server Setup log file!"
Pause
break
}
Else
{
## Get error(s) from log
$SetupLastError = $SetupLog | select-string -SimpleMatch -Pattern "Error:" | Select-Object -Last 1 #| ? {$_.Line -notlike "*Startup task*"}
If ($SetupLastError)
{
Write-Warning $SetupLastError.Line
#$SetupLastReturncode = $SetupLog | select-string -SimpleMatch -Pattern "Last return code" | Select-Object -Last 1
#If ($SetupLastReturnCode) {Write-Warning $SetupLastReturncode.Line}
Write-Host -ForegroundColor Blue " - Review the log file and try to correct any error conditions."
Pause
Invoke-Item $env:TEMP\$SetupLog
break
}
## Look for restart requirement in log
$SetupRestartNotNeeded = $SetupLog | select-string -SimpleMatch -Pattern "System reboot is not pending."
If (!($SetupRestartNotNeeded))
{
Write-Host -ForegroundColor Blue " - SharePoint setup requires a restart."
Write-Host -ForegroundColor Blue " - Run the script again after restarting to continue."
Pause
break
}
}
}
Else
{
Write-Host -ForegroundColor Red "- Install path $bits Not found!!"
Pause
break
}
}
}
InstallSharepoint
#End Region Install SharePoint Bits
#Region Install Language Packs
## Detects any language packs in $bits\LanguagePacks folder and installs them.
## Look for Server language packs
$ServerLanguagePacks = (Get-ChildItem "$bits\LanguagePacks" -Name -Include ServerLanguagePack*.exe -ErrorAction SilentlyContinue)
If ($ServerLanguagePacks)
{
Write-Host -ForegroundColor Blue "- Installing SharePoint (Server) Language Packs:"
## Get installed languages from registry (HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office Server\14.0\InstalledLanguages)
$InstalledOfficeServerLanguages = (Get-Item "HKLM:\Software\Microsoft\Office Server\14.0\InstalledLanguages").GetValueNames() | ? {$_ -ne ""}
ForEach ($LanguagePack in $ServerLanguagePacks)
{
## Slightly convoluted check to see if language pack is already installed, based on name of language pack file.
## This only works if you've renamed your language pack(s) to follow the convention "ServerLanguagePack_XX-XX.exe" where is a culture such as .
$Language = $InstalledOfficeServerLanguages | ? {$_ -eq (($LanguagePack -replace "ServerLanguagePack_","") -replace ".exe","")}
If (!$Language)
{
Write-Host -ForegroundColor Blue " - Installing $LanguagePack..." -NoNewline
Start-Process -FilePath "$bits\LanguagePacks\$LanguagePack" -ArgumentList "/quiet /norestart"
While (Get-Process -Name ($LanguagePack -replace ".exe", "") -ErrorAction SilentlyContinue)
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 5
}
Write-Host -BackgroundColor Blue -ForegroundColor Black "Done."
}
Else
{
Write-Host -ForegroundColor Blue " - Language $Language already appears to be installed, skipping."
}
}
Write-Host -ForegroundColor Blue " - Language Pack installation complete."
}
Else {Write-Host -ForegroundColor Blue " - No language packs found in $bits\LanguagePacks, skipping."}
#Get Installed Languages
$InstalledOfficeServerLanguages = (Get-Item "HKLM:\Software\Microsoft\Office Server\14.0\InstalledLanguages").GetValueNames() | ? {$_ -ne ""}
#List each installed Language
Write-Host -ForegroundColor Blue " - Currently installed languages:"
ForEach ($Language in $InstalledOfficeServerLanguages)
{
#Write-Host -ForegroundColor Blue " -"$Language.DisplayName
Write-Host -ForegroundColor Blue " -" ([System.Globalization.CultureInfo]::GetCultureInfo($Language).DisplayName)
}
#End Region Install Language Packs
#Region Configure First Farm or Join an Existing one
Write-Host -ForegroundColor Blue "- Creating & configuring (or joining) farm:"
Write-Host -ForegroundColor Blue " - Enabling SP PowerShell cmdlets..."
If ((Get-PsSnapin |?{$_.Name -eq "Microsoft.SharePoint.PowerShell"})-eq $null)
{
$PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue | Out-Null
}
Start-SPAssignment -Global | Out-Null
## Look for an existing farm and join the farm if not already joined, or create a new farm
try
{
Write-Host -ForegroundColor Blue " - Checking farm membership for $env:COMPUTERNAME in `"$ConfigDB`"..."
$SPFarm = Get-SPFarm | Where-Object {$_.Name -eq $ConfigDB} -ErrorAction SilentlyContinue
}
catch {""}
If ($SPFarm -eq $null)
{
try
{
Write-Host -ForegroundColor Blue " - Attempting to join farm on `"$ConfigDB`"..."
$ConnectFarm = Connect-SPConfigurationDatabase -DatabaseName "$ConfigDB" -Passphrase $SecPhrase -DatabaseServer "$DBServer" -ErrorAction SilentlyContinue
If (-not $?)
{
Write-Host -ForegroundColor Blue " - No existing farm found.`n - Creating config database `"$ConfigDB`"..."
## Waiting a few seconds seems to help with the Connect-SPConfigurationDatabase barging in on the New-SPConfigurationDatabase command; not sure why...
sleep 5
New-SPConfigurationDatabase –DatabaseName "$ConfigDB" –DatabaseServer "$DBServer" –AdministrationContentDatabaseName "$CentralAdminContentDB" –Passphrase $SecPhrase –FarmCredentials $Cred_Farm
If (-not $?) {throw}
Else {$FarmMessage = "- Done creating configuration database for farm."}
}
Else {$FarmMessage = "- Done joining farm."}
#Write-Host -ForegroundColor Blue " - Creating Version registry value (workaround for apparent bug in PS-based install)"
#New-ItemProperty -Path 'HKLM:\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\14.0\' -Name Version -Value '14.0.0.5114' -ErrorAction SilentlyContinue | Out-Null
}
catch
{
Write-Output $_
Pause
break
}
}
Else {$FarmMessage = "- $env:COMPUTERNAME is already joined to farm on `"$ConfigDB`"."}
Write-Host -ForegroundColor Blue $FarmMessage
#END Region Configure First Farm or Join an Existing one
#Region Configure Central Admin
if ($isCA -eq "Y" -or $isCA -eq "y")
{
Write-Host -ForegroundColor Blue "- Creating and configuring Central Administration..."
try
{
## Install Help Files
Write-Host -ForegroundColor Blue " - Installing Help Collection..."
Install-SPHelpCollection -All
## Secure resources
Write-Host -ForegroundColor Blue " - Securing Resources..."
Initialize-SPResourceSecurity
## Install Services
Write-Host -ForegroundColor Blue " - Installing Services..."
Install-SPService
## Install (all) features
Write-Host -ForegroundColor Blue " - Installing Features..."
$Features = Install-SPFeature –AllExistingFeatures -Force
## Create Central Admin
Write-Host -ForegroundColor Blue " - Creating Central Admin site..."
$NewCentralAdmin = New-SPCentralAdministration -Port $CentralAdminPort -WindowsAuthProvider "NTLM" -ErrorVariable err
If (-not $?) {throw}
Write-Host -ForegroundColor Blue " - Waiting for Central Admin site to provision..." -NoNewline
sleep 5
Write-Host -BackgroundColor Blue -ForegroundColor Black "Done!"
Write-Host -ForegroundColor Blue " - Installing Application Content..."
Install-SPApplicationContent
}
catch
{
If ($err -like "*update conflict*")
{
Write-Warning " - A concurrency error occured, trying again."
CreateCentralAdmin
}
Else
{
Write-Output $_
Pause
break
}
}
Write-Host -ForegroundColor Blue "- Done creating Central Administration."
}
#End Region Configure Central Admin
#Start SharePoint Web Services Root App Pool
$SPWebServRoot = Get-ChildItem IIS:\AppPools | where {$_.Name -eq "SharePoint Web Services Root"}
If ($SPWebServRoot.State -eq "Stopped")
{
try
{
Write-Host -ForegroundColor Blue "- Starting SharePoint Web Services Root App Pool..."
$SPWebServRoot | Start-WebAppPool | Out-Null
If (-not $?) {throw "- Failed to start SharePoint Web Services Root App Pool"}
}
catch {"- An error occurred starting the SharePoint Web Services Root App Pool"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for SharePoint Web Services Root App Pool to start" -NoNewline
While ($SPWebServRoot.State -ne "Started")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$SPWebServRoot = Get-ChildItem IIS:\AppPools | where {$_.Name -eq "SharePoint Web Services Root"}
}
Write-Host -ForegroundColor Blue "Started!"
}
#Region Provision Service Applications
if ($isCA -eq "Y" -or $isCA -eq "y")
{
Write-Host -ForegroundColor White " - ReAdding SharePoint Snap-In..."
Remove-PSSnapin Microsoft.SharePoint.PowerShell
$PSSnapin = Add-PsSnapin Microsoft.SharePoint.PowerShell
$searchServer = "$env:COMPUTERNAME"
#Get PSCred object for the Servicess App Pool Account
$SAAPAcctNode=$ServiceAccountsxml.selectSingleNode("//ServiceAccounts/ServiceAccount[@Name='$domServiceAppAP']")
$txtSAAPAcctPass = $SAAPAcctNode.Password
$SAAPAcctPWD = ConvertTo-SecureString "$txtSAAPAcctPass" -asplaintext -force
$cred_FarmSAAP = New-Object System.Management.Automation.PsCredential $domServiceAppAP,$SAAPAcctPWD
#Get PSCred object for the Shared Site App Pool Account
$SiteAPAcctNode=$ServiceAccountsxml.selectSingleNode("//ServiceAccounts/ServiceAccount[@Name='$domSiteAP']")
$txtSiteAPAcctPWD = $SiteAPAcctNode.Password
$SiteAPAcctPWD = ConvertTo-SecureString "$txtSiteAPAcctPWD" -asplaintext -force
$cred_FarmSiteAP = New-Object System.Management.Automation.PsCredential $domSiteAP,$SiteAPAcctPWD
## Add Managed Account for Services App Pool Account
$ManagedAccountGen = Get-SPManagedAccount | Where-Object {$_.UserName -eq "$domServiceAppAP"}
If ($ManagedAccountGen -eq $NULL)
{
Write-Host -ForegroundColor Blue "- Registering managed account" $domServiceAppAP
New-SPManagedAccount -Credential $cred_FarmSAAP | Out-Null
}
Else {Write-Host -ForegroundColor Blue "- Managed account "$domServiceAppAP" already exists, continuing."}
#Test/Create SharePoint Web Services App Pool
Write-Host -ForegroundColor Blue "- Getting Hosted Services Application Pool, creating if necessary..."
$SAAppPool = Get-SPServiceApplicationPool "SharePoint Web Services" -ea SilentlyContinue
if($SAAppPool -eq $null)
{
$SAAppPool = New-SPServiceApplicationPool "SharePoint Web Services" -account $domServiceAppAP
If (-not $?) { throw "Failed to create an application pool" }
}
## Add Managed Account for Portal App Pool Account
$ManagedAccountPortal = Get-SPManagedAccount | Where-Object {$_.UserName -eq $domSiteAP}
If ($ManagedAccountPortal -eq $NULL)
{
Write-Host -ForegroundColor Blue "- Registering managed account" $domSiteAP
New-SPManagedAccount -Credential $cred_FarmSiteAP | Out-Null
}
Else {Write-Host -ForegroundColor Blue "- Managed account $domSiteAP already exists, continuing."}
#EndRegion
#Region Start Common Services
#Start Sandboxed Code Service
$SandboxedCodeService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Administration.SPUserCodeServiceInstance"}
If ($SandboxedCodeService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Foundation Sandboxed Code Service..."
$SandboxedCodeService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Sandboxed Code Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Foundation Sandboxed Code Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Sandboxed Code service to start" -NoNewline
While ($SandboxedCodeService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$SandboxedCodeService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Administration.SPUserCodeServiceInstance"}
}
Write-Host -ForegroundColor Blue "Started!"
}
#Start Application Registry Service
$ApplicationRegistryService = Get-SPServiceInstance | ? {$_.TypeName -eq "Application Registry Service"}
If ($ApplicationRegistryService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Foundation Application Registry Service..."
$ApplicationRegistryService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Sandboxed Code Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Foundation Application Registry Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Application Registry service to start" -NoNewline
While ($ApplicationRegistryService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$ApplicationRegistryService = Get-SPServiceInstance | ? {$_.TypeName -eq "Application Registry Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
#Start Claims to Windows Service
$ClaimsToWindowsService = Get-SPServiceInstance | ? {$_.TypeName -eq "Claims to Windows Token Service"}
If ($ClaimsToWindowsService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Foundation Claims to Windows Token Service..."
$ClaimsToWindowsService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Sandboxed Code Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Foundation Claims to Windows Token Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Claims to Windows Token Service to start" -NoNewline
While ($ClaimsToWindowsService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$ClaimsToWindowsService = Get-SPServiceInstance | ? {$_.TypeName -eq "Claims to Windows Token Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
#Region Create BCS App
If ($CreateBCSServiceApp -eq "1")
{
Write-Host -ForegroundColor Blue "Creating BCS Service and Proxy..."
New-SPBusinessDataCatalogServiceApplication -Name $bcsSAName -ApplicationPool $SAAppPool -DatabaseServer $dbServer -DatabaseName "$BCSDB" > $null
$BCSService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Business Data Connectivity Service"}
If ($BCSService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Business Data Connectivity Service..."
$BCSService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Sandboxed Code Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Business Data Connectivity Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Business Data Connectivity Service to start" -NoNewline
While ($BCSService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$BCSService = Get-SPServiceInstance | ? {$_.TypeName -eq "Business Data Connectivity Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
#End Region
#Region Create Metadata Service Application
If ($CreateMetadataServiceApp -eq "1")
{
try
{
## Create a Metadata Service Application
If((Get-SPServiceApplication | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplication"}) -eq $null)
{
Write-Host -ForegroundColor Blue " - Creating Managed Metadata Service:"
## Get the service instance
$MetadataServiceInstance = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceInstance"}
If (-not $?) { throw "- Failed to find Metadata service instance" }
## Start Service instance
if($MetadataserviceInstance.Status -eq "Disabled")
{
Write-Host -ForegroundColor Blue " - Starting Metadata Service Instance..."
$MetadataServiceInstance | Start-SPServiceInstance | Out-Null
If (-not $?) { throw "- Failed to start Metadata service instance" }
}
## Wait
Write-Host -ForegroundColor Blue " - Waiting for Metadata service to start" -NoNewline
While ($MetadataServiceInstance.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$MetadataServiceInstance = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceInstance"}
}
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!"
## Create Service App
Write-Host -ForegroundColor Blue " - Creating Metadata Service Application..."
$MetaDataServiceApp = New-SPMetadataServiceApplication -Name $metadataSAName -ApplicationPool $SAAppPool -DatabaseName $MetaDataDB -AdministratorAccount $domFarmAcct -FullAccessAccount $domFarmAcct
If (-not $?) { throw "- Failed to create Metadata Service Application" }
## create proxy
Write-Host -ForegroundColor Blue " - Creating Metadata Service Application Proxy..."
$MetaDataServiceAppProxy = New-SPMetadataServiceApplicationProxy -Name "Metadata Service Application Proxy" -ServiceApplication $MetaDataServiceApp -DefaultProxyGroup
If (-not $?) { throw "- Failed to create Metadata Service Application Proxy" }
Write-Host -ForegroundColor Blue " - Granting rights to Metadata Service Application..."
## Get ID of "Managed Metadata Service"
$MetadataServiceAppToSecure = Get-SPServiceApplication | ? {$_.GetType().ToString() -eq "Microsoft.SharePoint.Taxonomy.MetadataWebServiceApplication"}
$MetadataServiceAppIDToSecure = $MetadataServiceAppToSecure.Id
## Create a variable that contains the list of administrators for the service application
$MetadataServiceAppSecurity = Get-SPServiceApplicationSecurity $MetadataServiceAppIDToSecure
## Create a variable that contains the claims principal for app pool and farm user accounts
$FarmSiteAPPrincipal = New-SPClaimsPrincipal -Identity $domSiteAP -IdentityType WindowsSamAccountName
## Give permissions to the claims principal you just created
Grant-SPObjectSecurity $MetadataServiceAppSecurity -Principal $FarmSiteAPPrincipal -Rights "Full Access to Term Store"
## Apply the changes to the Metadata Service application
Set-SPServiceApplicationSecurity $MetadataServiceAppIDToSecure -objectSecurity $MetadataServiceAppSecurity
Write-Host -ForegroundColor Blue "- Done creating Managed Metadata Service."
}
Else {Write-Host -ForegroundColor Blue "- Managed Metadata Service already exists."}
}
catch
{
Write-Output $_
}
}
#EndRegion
#Region Create Content Web Apps
$GetSPWebApplication = Get-SPWebApplication | Where-Object {$_.DisplayName -eq $PortalName}
If ($GetSPWebApplication -eq $Null)
{
Write-Host -ForegroundColor Blue "- Creating Web App `"$PortalName`"..."
If ($PortalUseClaims -eq "1")
{
## Configure new web app to use Claims-based authentication
$PortalAuthProvider = New-SPAuthenticationProvider -UseWindowsIntegratedAuthentication
New-SPWebApplication -Name $PortalName -ApplicationPoolAccount $domSiteAP -ApplicationPool $PortalAppPool -DatabaseName $PortalDB -HostHeader $PortalHostHeader -Url $PortalURL -Port $PortalPort -SecureSocketsLayer:$PortalUseSSL -AuthenticationProvider $PortalAuthProvider | Out-Null
}
Else
{
## Create the web app using Classic mode authentication
New-SPWebApplication -Name $PortalName -ApplicationPoolAccount $domSiteAP -ApplicationPool $PortalAppPool -DatabaseName $PortalDB -HostHeader $PortalHostHeader -Url $PortalURL -Port $PortalPort -SecureSocketsLayer:$PortalUseSSL | Out-Null
}
Write-Host -ForegroundColor Blue "- Creating Site Collection `"$PortalURL`"..."
## Verify that the Language we're trying to create the site in is currently installed on the server
$PortalCulture = [System.Globalization.CultureInfo]::GetCultureInfo(([convert]::ToInt32($PortalLCID)))
$PortalCultureDisplayName = $PortalCulture.DisplayName
If (!($InstalledOfficeServerLanguages | Where-Object {$_ -eq $PortalCulture.Name}))
{
Write-Warning " - You must install the `"$PortalCulture ($PortalCultureDisplayName)`" Language Pack before you can create a site using LCID $PortalLCID"
}
Else
{
New-SPSite -Url $PortalURL -OwnerAlias $domFarmAdmin -SecondaryOwnerAlias $domSiteAdmin -ContentDatabase $PortalDB -Description $PortalName -Name $PortalName -Template $PortalTemplate -Language $PortalLCID | Out-Null
Write-Host -ForegroundColor Blue "- Launching $PortalURL..."
Start-Process "${env:ProgramFiles(x86)}\Internet Explorer\iexplore.exe" "$PortalUrl" -WindowStyle Minimized
}
}
Else
{
Write-Host -ForegroundColor Blue "- Web app $PortalName already exists, continuing..."
}
#EndRegion
#Region Create User Profile Service Application
If ($CreateUserProfileApp -eq "1")
{
## Based on http://sharepoint.microsoft.com/blogs/zach/Lists/Posts/Post.aspx?ID=50
try
{
## Create a Profile Service Application
If ((Get-SPServiceApplication | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.UserProfileApplication"}) -eq $null)
{
## get the service instance
$ProfileServiceInstance = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.UserProfileServiceInstance"}
If (-not $?) { throw " - Failed to find User Profile Service instance" }
## Start Service instance
Write-Host -ForegroundColor Blue " - Starting User Profile Service instance..."
If (($ProfileServiceInstance.Status -eq "Disabled") -or ($ProfileServiceInstance.Status -ne "Online"))
{
$ProfileServiceInstance | Start-SPServiceInstance | Out-Null
If (-not $?) { throw " - Failed to start User Profile Service instance" }
## Wait
Write-Host -ForegroundColor Blue " - Waiting for User Profile Service to start" -NoNewline
While ($ProfileServiceInstance.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$ProfileServiceInstance = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.UserProfileServiceInstance"}
}
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!"
}
## Create MySites Web Application
$GetSPWebApplication = Get-SPWebApplication | Where-Object {$_.DisplayName -eq $MySiteName}
If ($GetSPWebApplication -eq $Null)
{
Write-Host -ForegroundColor Blue " - Creating Web App `"$MySiteName`"..."
New-SPWebApplication -Name $MySiteName -ApplicationPool $MySiteAppPool -DatabaseName $MySiteDB -HostHeader $MySiteHostHeader -Url $MySiteURL -Port $MySitePort -SecureSocketsLayer:$MySiteUseSSL | Out-Null
}
Else
{
Write-Host -ForegroundColor Blue " - Web app `"$MySiteName`" already exists, continuing..."
}
## Create MySites Site Collection
If ((Get-SPContentDatabase | Where-Object {$_.Name -eq $MySiteDB})-eq $null)
{
Write-Host -ForegroundColor Blue " - Creating My Sites content DB..."
$NewMySitesDB = New-SPContentDatabase -Name $MySiteDB -WebApplication "$MySiteURL`:$MySitePort"
If (-not $?) { throw " - Failed to create My Sites content DB" }
}
If ((Get-SPSite | Where-Object {$_.Url -eq "$MySiteURL`:$MySitePort"})-eq $null)
{
Write-Host -ForegroundColor Blue " - Creating My Sites site collection $MySiteURL`:$MySitePort..."
## Verify that the Language we're trying to create the site in is currently installed on the server
$MySiteCulture = [System.Globalization.CultureInfo]::GetCultureInfo(([convert]::ToInt32($MySiteLCID)))
$MySiteCultureDisplayName = $MySiteCulture.DisplayName
If (!($InstalledOfficeServerLanguages | Where-Object {$_ -eq $MySiteCulture.Name}))
{
Write-Warning " - You must install the `"$MySiteCulture ($MySiteCultureDisplayName)`" Language Pack before you can create a site using LCID $MySiteLCID"
Pause
break
}
Else
{
$NewMySitesCollection = New-SPSite -Url "$MySiteURL`:$MySitePort" -OwnerAlias $domFarmAdmin -SecondaryOwnerAlias $domSiteAdmin -ContentDatabase $MySiteDB -Description $MySiteName -Name $MySiteName -Template $MySiteTemplate -Language $MySiteLCID | Out-Null
If (-not $?) {throw " - Failed to create My Sites site collection"}
}
}
## Create Service App
Write-Host -ForegroundColor Blue " - Creating $userProfileSAName..."
#$ProfileServiceApp = New-SPProfileServiceApplication -Name "$userProfileSAName" -ApplicationPool $SAAppPool -ProfileDBName $ProfileDB -ProfileSyncDBName $SyncDB -SocialDBName $SocialDB -SyncInstanceMachine $env:COMPUTERNAME -MySiteHostLocation "$MySiteURL`:$MySitePort"
$ProfileServiceApp = New-SPProfileServiceApplication -Name "$userProfileSAName" -ApplicationPool $SAAppPool -ProfileDBName $ProfileDB -ProfileSyncDBName $SyncDB -SocialDBName $SocialDB -MySiteHostLocation "$MySiteURL`:$MySitePort"
If (-not $?) { throw " - Failed to create $userProfileSAName" }
## Create Proxy
Write-Host -ForegroundColor Blue " - Creating $userProfileSAName Proxy..."
$ProfileServiceAppProxy = New-SPProfileServiceApplicationProxy -Name "$userProfileSAName Proxy" -ServiceApplication $ProfileServiceApp -DefaultProxyGroup
If (-not $?) { throw " - Failed to create $userProfileSAName Proxy" }
## Get ID of $userProfileSAName
Write-Host -ForegroundColor Blue " - Get ID of $userProfileSAName..."
$ProfileServiceAppToSecure = Get-SPServiceApplication |?{$_.Name -eq $userProfileSAName}
$ProfileServiceAppIDToSecure = $ProfileServiceAppToSecure.Id
Write-Host -ForegroundColor Blue " - Granting rights to $userProfileSAName..."
## Create a variable that contains the guid for the User Profile service for which you want to delegate Full Control
$serviceapp = Get-SPServiceApplication $ProfileServiceAppIDToSecure
## Create a variable that contains the list of administrators for the service application
$ProfileServiceAppSecurity = Get-SPServiceApplicationSecurity $serviceapp -Admin
## Create a variable that contains the claims principal for app pool and farm user accounts
$FarmSiteAPPrincipal = New-SPClaimsPrincipal -Identity $domSiteAP -IdentityType WindowsSamAccountName
$FarmAcctPrincipal = New-SPClaimsPrincipal -Identity $domFarmAcct -IdentityType WindowsSamAccountName
## Give Full Control permissions to the claims principal you just created, and the Farm Account
Grant-SPObjectSecurity $ProfileServiceAppSecurity -Principal $FarmSiteAPPrincipal -Rights "Full Control"
Grant-SPObjectSecurity $ProfileServiceAppSecurity -Principal $FarmAcctPrincipal -Rights "Full Control"
## Apply the changes to the User Profile service application
Set-SPServiceApplicationSecurity $serviceapp -objectSecurity $ProfileServiceAppSecurity -Admin
## Launch My Site host
Write-Host -ForegroundColor Blue " - Launching $MySiteURL`:$MySitePort..."
Start-Process "$MySiteURL`:$MySitePort" -WindowStyle Minimized
Write-Host -ForegroundColor Blue "- Done creating $userProfileSAName."
}
Function Fix-DBOwner
{
## Thanks to Gary Lapointe via Andrew Woodward for the SQL script below to change dbo to $domFarmAcct
## Needed if we are using an account other than $domFarmAcct to install SharePoint
## AMW 09/09/2010 - fix up the database for the profile database ownership
$ProfileServiceApp = Get-SPServiceApplication |?{$_.Name -eq $userProfileSAName}
If ($ProfileServiceApp)
{
Write-Host -ForegroundColor Blue "- Fixing SQL ownership for profile database: $DBServer\$ProfileDB..."
$sqlCmd = New-Object System.Data.SqlClient.SqlCommand
$sqlCmd.CommandType = "Text"
#$sqlCmd.CommandText = "ALTER USER [$domFarmAcct] WITH DEFAULT_SCHEMA=dbo;"
$SqlCmd.CommandText = "exec sp_dropuser `'$domFarmAcct`'; exec sp_changedbowner `'$domFarmAcct`';"
$connString = "Integrated Security=SSPI;Persist Security Info=False;Data Source=$DBServer;Initial Catalog=$ProfileDB;"
$connection = New-Object System.Data.SqlClient.SqlConnection($connString)
try
{
$connection.Open()
$sqlCmd.Connection = $connection
$sqlCmd.ExecuteNonQuery()
}
catch
{
Write-Output $_
}
finally
{
$connection.Dispose()
}
}
}
If (!($RunningAsFarmAcct)) {Fix-DBOwner}
## Start User Profile Synchronization Service
## Get User Profile Service
$ProfileServiceApp = Get-SPServiceApplication |?{$_.Name -eq $userProfileSAName}
If ($ProfileServiceApp)
{
## Get User Profile Synchronization Service
Write-Host -ForegroundColor Blue "- Checking User Profile Synchronization Service..." -NoNewline
$ProfileSyncService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.ProfileSynchronizationServiceInstance"}
If ($ProfileSyncService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "`n"
Write-Host -ForegroundColor Blue " - Starting User Profile Synchronization Service..." -NoNewline
$ProfileServiceApp.SetSynchronizationMachine($env:COMPUTERNAME, $ProfileSyncService.Id, $domFarmAcct, $txtFarmAcctPWD)
#If ($ProfileSyncService.Status -eq "Provisioning") {Write-Host -ForegroundColor Blue " - Waiting for User Profile Service Synchronization Service to start provisioning..." -NoNewline}
#ElseIf
If (($ProfileSyncService.Status -ne "Provisioning") -and ($ProfileSyncService.Status -ne "Online")) {Write-Host -ForegroundColor Blue " - Waiting for User Profile Synchronization Service to be started..." -NoNewline}
Else ## Monitor User Profile Sync service status
{
While ($ProfileSyncService.Status -ne "Online")
{
While ($ProfileSyncService.Status -ne "Provisioning")
{
Write-Host -ForegroundColor Blue ".`a" -NoNewline
Sleep 1
$ProfileSyncService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.ProfileSynchronizationServiceInstance"}
}
If ($ProfileSyncService.Status -eq "Provisioning")
{
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!`a`a"
Write-Host -ForegroundColor Blue " - Provisioning User Profile Sync Service, please wait (up to 15 minutes)..." -NoNewline
}
While($ProfileSyncService.Status -eq "Provisioning" -and $ProfileSyncService.Status -ne "Disabled")
{
Write-Host -ForegroundColor Blue ".`a" -NoNewline
sleep 1
$ProfileSyncService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Administration.ProfileSynchronizationServiceInstance"}
}
If ($ProfileSyncService.Status -ne "Online")
{
Write-Host -ForegroundColor Red ".`a`a`a`a`a`a`a`a"
Write-Host -BackgroundColor Red -ForegroundColor Black "- User Profile Synchronization Service could not be started!"
break
}
Else
{
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!`a`a"
## Need to restart IIS before we can do anything with the User Profile Sync Service
Write-Host -ForegroundColor Blue " - Restarting IIS..."
Start-Process -FilePath iisreset.exe -ArgumentList "-noforce" -Wait -NoNewWindow
}
}
}
}
Else {Write-Host -ForegroundColor Blue "Already started."}
}
Else
{
Write-Host -ForegroundColor Blue "`n"
Write-Host -ForegroundColor Red "- Could not get User Profile Service"
}
}
catch
{
Write-Output $_
}
}
#EndRegion
#Region Create $stateSAName
If ($CreateStateServiceApp -eq "1")
{
try
{
$GetSPStateServiceApplication = Get-SPStateServiceApplication
If ($GetSPStateServiceApplication -eq $Null)
{
Write-Host -ForegroundColor Blue "- Creating $stateSAName..."
New-SPStateServiceDatabase -Name $StateServiceDB | Out-Null
New-SPStateServiceApplication -Name $stateSAName -Database $StateServiceDB | Out-Null
Get-SPStateServiceDatabase | Initialize-SPStateServiceDatabase | Out-Null
Write-Host -ForegroundColor Blue " - Creating $stateSAName Proxy..."
Get-SPStateServiceApplication | New-SPStateServiceApplicationProxy -Name "$stateSAName Proxy" -DefaultProxyGroup | Out-Null
Write-Host -ForegroundColor Blue "- Done creating $stateSAName."
}
Else {Write-Host -ForegroundColor Blue "- $stateSAName exists, continuing..."}
}
catch
{
Write-Output $_
}
}
#EndRegion
#Region Create WSS Usage Application
If ($CreateWSSUsageApp -eq "1")
{
try
{
$GetSPUsageApplication = Get-SPUsageApplication
If ($GetSPUsageApplication -eq $Null)
{
Write-Host -ForegroundColor Blue "- Creating $usageSAName..."
New-SPUsageApplication -Name $usageSAName -DatabaseServer $dbServer -DatabaseName "$WSSUsageDB" -UsageService $serviceInstance > $null
$up = get-spserviceapplicationproxy | where {$_.DisplayName -eq "Usage and Health Data Collection Service"}
$up.provision()
Write-Host -ForegroundColor Blue "- Done Creating WSS Usage Application."
}
Else {Write-Host -ForegroundColor Blue "- $usageSAName exists, continuing..."}
}
catch
{
Write-Output $_
}
}
#EndRegion
#Region Create Secure Store Service Application
If ($CreateSecureStoreServiceApp -eq "1")
{
try
{
Write-Host -ForegroundColor Blue "- Creating Secure Store Service..."
$GetSPSecureStoreServiceApplication = Get-SPServiceApplication | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication])}
If ($GetSPSecureStoreServiceApplication -eq $Null)
{
## Get the service instance
$SecureStoreServiceInstance = Get-SPServiceInstance | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance])}
if (-not $?) { throw "- Failed to find Secure Store service instance" }
## Start Service instance
if($SecureStoreServiceInstance.Status -eq "Disabled")
{
Write-Host -ForegroundColor Blue " - Starting Secure Store Service Instance..."
$SecureStoreServiceInstance | Start-SPServiceInstance | Out-Null
if (-not $?) { throw "- Failed to start Secure Store service instance" }
## Wait
Write-Host -ForegroundColor Blue " - Waiting for Secure Store service to start" -NoNewline
While ($SecureStoreServiceInstance.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$SecureStoreServiceInstance = Get-SPServiceInstance | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceInstance])}
}
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!"
}
Write-Host -ForegroundColor Blue " - Creating Secure Store Service Application..."
New-SPSecureStoreServiceApplication -Name "Secure Store Service" -PartitionMode:$false -Sharing:$false -DatabaseName $SecureStoreDB -ApplicationPool $SAAppPool -AuditingEnabled:$true -AuditLogMaxSize 30 | Out-Null
Write-Host -ForegroundColor Blue " - Creating Secure Store Service Application Proxy..."
Get-SPServiceApplication | ? {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplication])} | New-SPSecureStoreServiceApplicationProxy -Name "Secure Store Service Proxy" -DefaultProxyGroup | Out-Null
Write-Host -ForegroundColor Blue " - Done creating Secure Store Service Application."
}
Else {Write-Host -ForegroundColor Blue " - Secure Store Service Application exists, continuing..."}
$secureStore=Get-SPServiceApplicationProxy | Where {$_.GetType().Equals([Microsoft.Office.SecureStoreService.Server.SecureStoreServiceApplicationProxy])}
Write-Host -ForegroundColor Blue " - Creating the Master Key..."
Update-SPSecureStoreMasterKey -ServiceApplicationProxy $secureStore.Id -Passphrase "$FarmPassPhrase"
Start-Sleep -s 5
Write-Host -ForegroundColor Blue " - Creating the Application Key..."
Update-SPSecureStoreApplicationServerKey -ServiceApplicationProxy $secureStore.Id -Passphrase "$FarmPassPhrase" -ErrorAction SilentlyContinue
If (!$?)
{
## Try again...
Start-Sleep -s 5
Write-Host -ForegroundColor Blue " - Creating the Application Key (2nd attempt)..."
Update-SPSecureStoreApplicationServerKey -ServiceApplicationProxy $secureStore.Id -Passphrase "$FarmPassPhrase"
}
Write-Host -ForegroundColor Blue " - Setting the unattended account for Performance Point Services..."
Get-SPPerformancePointServiceApplication | Set-SPPerformancePointSecureDataValues -DataSourceUnattendedServiceAccount $cred_farm
}
catch
{
Write-Output $_
}
Write-Host -ForegroundColor Blue "- Done creating/configuring Secure Store Service."
}
#EndRegion
#Region Start Search Query and Site Settings Service
If ($StartSearchQueryAndSiteSettingsService -eq "1")
{
try
{
## Get the service instance
$SearchQueryAndSiteSettingsService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Search.Administration.SearchQueryAndSiteSettingsServiceInstance"}
If (-not $?) { throw "- Failed to find Search Query and Site Settings service instance" }
## Start Service instance
Write-Host -ForegroundColor Blue "- Starting Search Query and Site Settings Service Instance..."
if($SearchQueryAndSiteSettingsService.Status -eq "Disabled")
{
$SearchQueryAndSiteSettingsService | Start-SPServiceInstance | Out-Null
If (-not $?) { throw " - Failed to start Search Query and Site Settings service instance" }
## Wait
Write-Host -ForegroundColor Blue " - Waiting for Search Query and Site Settings service to start" -NoNewline
While ($SearchQueryAndSiteSettingsService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
start-sleep 1
$SearchQueryAndSiteSettingsService = Get-SPServiceInstance | ? {$_.GetType().ToString() -eq "Microsoft.Office.Server.Search.Administration.SearchQueryAndSiteSettingsServiceInstance"}
}
Write-Host -BackgroundColor Blue -ForegroundColor Black "Started!"
}
Else {Write-Host -ForegroundColor Blue "- Search Query and Site Settings Service already started, continuing..."}
}
catch
{
Write-Output $_
}
}
#EndRegion
#Region Setup Enterprise Search
# Original script for SharePoint 2010 beta2 by Gary Lapointe ()
#
# Modified by Søren Laurits Nielsen (soerennielsen.wordpress.com):
#
# Modified to fix some errors since some cmdlets have changed a bit since beta 2 and added support for "ShareName" for
# the query component. It is required for non DC computers.
#
# Modified to support "localhost" moniker in config file.
#
# Note: Accounts, Shares and directories specified in the config file must be setup before hand.
If ($StartEnterpriseSearch -eq "1")
{
Write-Host -ForegroundColor Blue "Creating Search Service and Proxy..."
Write-Host -ForegroundColor Blue " Starting Services..."
Start-SPEnterpriseSearchServiceInstance $searchServer
Start-SPEnterpriseSearchQueryAndSiteSettingsServiceInstance $searchServer
Write-Host -ForegroundColor Blue " Creating Search Application..."
$searchApp = New-SPEnterpriseSearchServiceApplication -Name $searchSAName -ApplicationPool $SAAppPool -DatabaseServer $dbServer -DatabaseName "$SearchDB"
$searchInstance = Get-SPEnterpriseSearchServiceInstance $searchServer
Write-Host -ForegroundColor Blue " Creating Administration Component..."
$searchApp | Get-SPEnterpriseSearchAdministrationComponent | Set-SPEnterpriseSearchAdministrationComponent -SearchServiceInstance $searchInstance
##Crawl
Write-Host -ForegroundColor Blue " 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 -ForegroundColor Blue " 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 -ForegroundColor Blue " Creating Proxy..."
$searchAppProxy = New-SPEnterpriseSearchServiceApplicationProxy -Name "$searchSAName Proxy" -SearchApplication $searchSAName > $null
## Finally, set the crawl start addresses (including the elusive sps3:// URL required for People Search:
$CrawlStartAddresses = $PortalURL+":"+$PortalPort+","+$MySiteURL+":"+$MySitePort+",sps3://"+$MySiteHostHeader+":"+$MySitePort
Get-SPEnterpriseSearchServiceApplication | Get-SPEnterpriseSearchCrawlContentSource | Set-SPEnterpriseSearchCrawlContentSource -StartAddresses $CrawlStartAddresses
}
#EndRegion
If ($CreateWebAnalytics = "1")
{
Write-Host -ForegroundColor Blue "Creating Web Analytics Service and Proxy..."
$stagerSubscription = ""
$reportingSubscription = ""
New-SPWebAnalyticsServiceApplication -Name $WebAnalyticsSAName -ApplicationPool $SAAppPool -ReportingDataRetention 20 -SamplingRate 100 -ListOfReportingDatabases $reportingSubscription -ListOfStagingDatabases $stagerSubscription > $null
New-SPWebAnalyticsServiceApplicationProxy -Name "$WebAnalyticsSAName Proxy" -ServiceApplication $WebAnalyticsSAName > $null
#Start Web Analytics Web Service
$WAWebService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Web Service"}
If ($WAWebService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Web Analytics Web Service..."
$WAWebService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Web Analytics Web Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Web Analytics Web Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Web Analytics Web Service to start" -NoNewline
While ($WAWebService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$WAWebService = Get-SPServiceInstance | ? {$_.TypeName -eq "Web Analytics Web Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
#Start Web Analytics Data Processing Service
$WADPService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Web Analytics Data Processing Service"}
If ($WADPService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Web Analytics Data Processing Service..."
$WADPService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Web Analytics Data Processing Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Web Analytics Data Processing Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Web Analytics Data Processing Service to start" -NoNewline
While ($WADPService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$WADPService = Get-SPServiceInstance | ? {$_.TypeName -eq "Web Analytics Data Processing Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
If ($CreateVisioApp = "1")
{
Write-Host -ForegroundColor Blue "Creating Visio Graphics Service and Proxy..."
New-SPVisioServiceApplication -Name $visioSAName -ApplicationPool $SAAppPool > $null
New-SPVisioServiceApplicationProxy -Name "$visioSAName Proxy" -ServiceApplication $visioSAName > $null
#Start Visio Service
$VisioService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Visio Graphics Service"}
If ($VisioService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Visio Graphics Service..."
$VisioService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Visio Graphics Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Visio Graphics Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Visio Graphics Service to start" -NoNewline
While ($VisioService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$VisioService = Get-SPServiceInstance | ? {$_.TypeName -eq "Visio Graphics Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
If ($CreatePerformancePoint = "1")
{
Write-Host -ForegroundColor Blue "Creating Performance Point Service and Proxy..."
New-SPPerformancePointServiceApplication -Name $performancePointSAName -ApplicationPool $SAAppPool > $null
New-SPPerformancePointServiceApplicationProxy -Default -Name "$performancePointSAName Proxy" -ServiceApplication $performancePointSAName > $null
#Start PerformancePoint Service
$PPService = Get-SPServiceInstance | where-object {$_.TypeName -eq "PerformancePoint Service"}
If ($PPService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint PerformancePoint Service..."
$PPService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start PerformancePoint Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint PerformancePoint Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for PerformancePoint Service to start" -NoNewline
While ($PPService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$PPService = Get-SPServiceInstance | ? {$_.TypeName -eq "PerformancePoint Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
If ($CreateAccessApp = "1")
{
Write-Host -ForegroundColor Blue "Creating Access Services and Proxy..."
New-SPAccessServiceApplication -Name $accesssSAName -ApplicationPool $SAAppPool > $null
#Start Access Database Service
$AccessService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Access Database Service"}
If ($AccessService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Access Database Service..."
$AccessService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Access Database Service"}
}
catch {"- An error occurred starting the Microsoft SharePoint Access Database Service"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Access Database Service to start" -NoNewline
While ($AccessService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$AccessService = Get-SPServiceInstance | ? {$_.TypeName -eq "Access Database Service"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
If ($CreateExcelApp = "1")
{
Write-Host -ForegroundColor Blue "Creating Excel Service..."
New-SPExcelServiceApplication -name $excelSAName –ApplicationPool $SAAppPool > $null
Set-SPExcelFileLocation -Identity "http://" -ExcelServiceApplication $excelSAName -ExternalDataAllowed 2 -WorkbookSizeMax 10 -WarnOnDataRefresh:$true
#Start Excel Calculation Services
$ExcelService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Excel Calculation Services"}
If ($ExcelService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Excel Calculation Services..."
$ExcelService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Excel Calculation Services"}
}
catch {"- An error occurred starting the Microsoft SharePoint Excel Calculation Services"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Excel Calculation Services to start" -NoNewline
While ($ExcelService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$ExcelService = Get-SPServiceInstance | ? {$_.TypeName -eq "Excel Calculation Services"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
If ($CreateWordApp = "1")
{
Write-Host -ForegroundColor Blue "Creating Word Conversion Service and Proxy..."
New-SPWordConversionServiceApplication -Name $WordAutomationSAName -ApplicationPool $SAAppPool -DatabaseServer $dbServer -DatabaseName "$WordAutomationDB" -Default > $null
#Start Word Automation Services
$WordService = Get-SPServiceInstance | where-object {$_.TypeName -eq "Word Automation Services"}
If ($WordService.Status -eq "Disabled")
{
try
{
Write-Host -ForegroundColor Blue "- Starting Microsoft SharePoint Word Automation Services..."
$WordService | Start-SPServiceInstance | Out-Null
If (-not $?) {throw "- Failed to start Word Automation Services"}
}
catch {"- An error occurred starting the Microsoft SharePoint Word Automation Services"}
#Wait
Write-Host -ForegroundColor Blue " - Waiting for Word Automation Services to start" -NoNewline
While ($WordService.Status -ne "Online")
{
Write-Host -ForegroundColor Blue "." -NoNewline
sleep 1
$WordService = Get-SPServiceInstance | ? {$_.TypeName -eq "Word Automation Services"}
}
Write-Host -ForegroundColor Blue "Started!"
}
}
}
#End Region Provision Service Applications