Automating Your SharePoint 2010 Installation
SharePoint 2010 can be installed in two ways: using a wizard or using Windows PowerShell. With the wizard, you will have to go through various steps that will help you configure your SharePoint 2010 installation. Figure 1 shows the steps required by the wizard.
However, using Windows PowerShell when installing SharePoint 2010 will not only give you more options to control the setup, but it will also allow you to reuse the code over and over again, achieving the exact same result.
Let’s take a look at the PowerShell commands that are required to automate your SharePoint 2010 installation.
STEP 1 – Creating a New Configuration Database
The first thing you will need to do is create a configuration database, which is the heart of a SharePoint farm and contains, more or less, all global settings. Without the configuration database, a SharePoint farm would not function. You can create a new configuration database using the New- SPConfigurationDatabase cmdlet. So how would you use the cmdlet? It’s pretty simple. If you want to find out more about a cmdlet in Windows PowerShell, you should use Get-help as demonstrated below:
PS > Get-Help New-SPConfigurationDatabase –Full
The example above displays the full Help topic for the New-SPConfigurationDatabase cmdlet, describing what the cmdlet does, the cmdlet’s parameters, and even examples on how to use the cmdlet. In this white paper, you will learn about the parameters listed below:
• DatabaseName – New configuration database name
• DatabaseServer – Database server instance
• AdministrationContentDatabaseName – Name for the Central Administration Database
• Passphrase – Specify a secure Password phrase, which is used to join other servers to the farm
• FarmCredentials – Specifies credentials for the Farm Administrator account
So, to begin, let’s specify the name of the database. Storing information in variables will allow us to reuse the variables:
PS > $databaseName = "SharePointConfigDB"
Next, you can store the database server name and the Central Administration database name in variables:
PS > $databaseServer = "SQLServer01" PS > $centralAdminDatabase = "SharePointAdminContentDB"
A passphrase is a new addition in SharePoint 2010 and is a “farm password” used when, for example, you’re connecting new servers to a farm. The Passphrase requires a slightly different approach since the Passphrase parameter accepts a SecureString as input. Lucky for us, Windows PowerShell includes a cmdlet, ConvertTo-SecureString, which converts a string to a secure string:
PS > $securePassPhrase = ConvertTo-SecureString -String "J0inD0main" -AsPlainText -Force
The FarmCredentials parameter requires an object of the type PSCredential. You can store such an object either by using the Get-Credential cmdlet or by using the New-Object cmdlet and specify what type of object instance you want to create. The example below shows how you can use the Get- Credential cmdlet:
PS > $psCredentials = Get-Credential
You will see that a dialogue box is prompted when using the Get-Credential cmdlet as shown in Figure 2. After you type the User name and Password and click enter, the Credentials are stored in an instance of a PSCredential object which you can then access through the variable.
Another way of storing an instance of a PSCredential object in a variable is by using the New-Object cmdlet. First, you store the accounts password in a variable using the ConvertTo-SecureString cmdlet:
PS > $securePassword = ConvertTo-SecureString -String "Password1" -AsPlainText -Force
Next, you use the New-Object cmdlet to create an instance of a .NET object:
PS > $psCredentials = New-Object -TypeName System.Management.Automation.PSCredential ' >> -ArgumentList "powershell\administrator", $securePassword
Now, you can simply use the variables as input to the New-PConfigurationDatabase cmdlet as shown below:
PS > New-SPConfigurationDatabase -DatabaseName $databaseName ' >> –DatabaseServer $databaseServer ' >> -AdministrationContentDatabaseName $centralAdminDatabase ' >> -Passphrase $securePassPhrase -FarmCredentials $psCredentials
STEP 2 – Install Help Files
After the configuration database is created, it’s time to install the provided Help site collection files. In most cases, you will use the All parameter to install all available Help collections as demonstrated below:
PS > Install-SPHelpCollection –All
STEP 3 – Enforce Security
It is also a good idea to enforce security for all resources, including files, folders, and registry keys. You can do this by using the Initialize- SPResourceSecurity cmdlet:
PS > Initialize-SPResourceSecurity
You’re almost there! Just four more steps to complete your SharePoint 2010 installation. For the rest of the instructions and more valuable white papers, visit Secrets of SharePoint.
Want to Learn More?
Many of the examples in this white paper are available in the book “PowerShell for SharePoint 2010 Administrators“, which is available at amazon.com. Check it out for more cool examples.
About the Authors
Niklas Goude is an author, IT consultant, and trainer at Truesec in Stockholm, Sweden. He is a Windows PowerShell expert, with extensive experience in automating and implementing SharePoint environments. Niklas has written a PowerShell book for Swedish IT professionals, www.powershell.se, and co-authored a book with Mattias Karlsson titled, PowerShell for Microsoft SharePoint 2010 Administrators. Niklas runs the blog, www.powershell.nu, where he shares scripts, examples, and solutions for administrative tasks in Windows environments using Windows PowerShell.
Mattias Karlsson is a senior consultant working for Enfo Zipper in Gothenburg, Sweden, a Microsoft Gold Partner company. Mattias has a long experience with SharePoint and has a background in technical documentation and project communication. His SharePoint experience focuses mainly on solution architecting, implementation and operations of SharePoint environments in midsize to large enterprise companies. Mattias runs the popular blog www.mysharepointofview.com and is a frequent trainer and speaker at SharePoint events.
Idera’s PowerShell Plus
Idera’s PowerShell Plus is the most advanced PowerShell IDE available today, helping administrators and developers quickly master the PowerShell scripting language while dramatically increasing the productivity of both novice and expert users. With PowerShell Plus users can learn PowerShell fast using the Interactive Learning Center and execute PowerShell quickly and accurately with the powerful interactive console. They can harness the power of the PowerShell community by accessing hundreds of pre-loaded scripts in the personal QuickClick library and downloading thousands of community scripts from PowerShell.com, TechNet and PoshCode directly from the PowerShell Plus console and editor. Users are able to debug PowerShell 10x faster with the advanced script editor. Editor Snippets provide many predefined code blocks for Windows PowerShell 2.0 features including Advanced Functions, Comment-Based Help, Jobs, Modules, and Remoting. Plus, the tool discovers modules automatically and loads them into PowerShell Plus for immediate use.
The latest version of PowerShell Plus includes a completely revamped user interface with the ability to further customize the console making it even easier to learn and master PowerShell.
PowerShell Plus is value priced at $199 per user.
Written by Niklas Goude and Mattias Karlsson. Reprinted with permission from Secrets of SharePoint.