I'm excited about PowerShell scripting in SharePoint 2010. We employ strict separation of duties, and the ability to script tasks for the administrator is high on my list of anticipated features. This is the first in a series of posts on scripting administrative functions in SharePoint.
Let’s start by creating a new Farm. I assume you are running these scripts on a single server with all SharePoint 2010 components installed. If you need help creating the environment, I started with
SharePoint Server 2010 RTM Virtual Machine Setup Guide (v1.6) (you have to register).
First, you need to add the SharePoint snap-in.
1
2
|
Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0
Clear-Host
|
Then, you will need to create a service account in the domain that the farm will run as. I didn’t script this, just use Active Directory Domains and Computers. Note that there is no service called “the farm”. The service account that you specify here will have access to the configuration and content databases and be used to run the IIS application pool that hosts central administration and a few other services.
Next, let’s set up a few variables. You need the service account name and password you just created, and the name of the SQL Server. In addition, you need to pick a name the configuration database and a content database that will hold the configuration for central administration. You can name these anything you want, but they have to be unique.
1
2
3
4
5
|
$FarmAccountName = "DOMAIN\SERVICE_ACCOUNT"
$Passphrase = "PASSWORD"
$DatabaseServer = "DATABASE_SERVER_NAME"
$ConfigDatabase = "Config"
$ContentDatabase = "Content_Admin"
|
Now, we can create the database. This script will ask you to enter the password for the service account and configure the required databases.
1
2
3
|
$FarmAccount = Get-Credential $FarmAccountName
$Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $ContentDatabase -Passphrase $Passphrase -FarmCredentials $FarmAccount
|
Next, we can configure the farm. This script will install services and features.
1
2
3
|
Initialize-SPResourceSecurity
Install-SPService
Install-SPFeature -AllExistingFeatures
|
Finally, we can configure the central administration site. This script will create a new IIS web site and application pool. It is configured to listen to all http traffic on port 8080. Note that you should probably use https here. I will explore this in a later post.
1
2
3
|
New-SPCentralAdministration -Port 8080 -WindowsAuthProvider NTLM
Install-SPHelpCollection -All
Install-SPApplicationContent
|
At this point you should be able to test the site.
http://locahost:8080
Here is the full script.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
Add-PSSnapin Microsoft.SharePoint.Powershell -EA 0
Clear-Host
$FarmAccountName = "DOMAIN\SERVICE_ACCOUNT"
$Passphrase = "PASSWORD"
$DatabaseServer = "DATABASE_SERVER_NAME"
$ConfigDatabase = "Config"
$ContentDatabase = "Content_Admin"
Write-Host "Creating Configuration Database"
$FarmAccount = Get-Credential $FarmAccountName
$Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $ContentDatabase -Passphrase $Passphrase -FarmCredentials $FarmAccount
Write-Host "Configuring Farm"
Initialize-SPResourceSecurity
Install-SPService
Install-SPFeature -AllExistingFeatures
Write-Host "Configuring Central Administration"
New-SPCentralAdministration -Port 8080 -WindowsAuthProvider NTLM
Install-SPHelpCollection -All
Install-SPApplicationContent
|