Create a SharePoint 2013 Farm Configuration with PowerShell
Installing SharePoint 2013 can be a relatively simple process, but there are a few “gotchas” waiting for the uninitiated. I”ll focus on one of these gotchas in this article, which describes the process of creating the SharePoint 2013 farm creation using PowerShell.
The farm configuration is typically performed right after installation of the first SharePoint server in a farm. In fact, by default the farm configuration wizard will kick off with the last screen of the SharePoint 2013 Server Installation Wizard.
PowerShell vs the Farm Configuration Wizard
Reasons to avoid using the built-in SharePoint Products Configuration Wizard:
- The Farm Configuration Wizard makes assumptions about the service application that you want installed.
- It makes assumptions about how you want your service applications configured.
- It auto-generates the database names for content databases and service application databases, which will include long and hard-to-read GUIDs for the web and service applications.
Reasons to use PowerShell to perform the SharePoint configuration:
- Taking control over the details of the SharePoint Farm Configuration with PowerShell allows us to have only the service applications we want.
- Service applications will be configured in just the way we want them.
- Databases are named during the creation by the script, so that naming conventions are adhered to and database names are consistent and easy to read.
This article starts from the point right after you’ve performed the SharePoint 2013 Server installation. Since you should already be installed and ready to configure the farm, I’ll leave the requirements for service accounts and necessary permissions for another article. However, if you need a review of those items, check out the Deployment Guide for SharePoint 2013 from Microsoft.
Also, the commands we work with will be part of the SharePoint module for PowerShell. This means you either need to run the SharePoint command shell, or you’ll need to import the commands to perform SharePoint administration with PowerShell (in either a standard PowerShell session or the ISE).
If (!(Get-PSSnapin | Where-Object –Property “Name” -eq –Value $SPAddin)) | `
SharePoint User Accounts
To perform the basic farm configuration, I’ll be using a few service accounts as examples. The number of service accounts you will use may be very different based on your security requirements and SharePoint architecture.
- SVC_SPSetup – The SharePoint Setup account
Used to install SharePoint
- SVC_SPFarm – The SharePoint farm account
Configures the farm and runs the Central Administration site
Used to run the Service Applications
Used as an application ID for a web application
Farm Installation with PowerShell
A basic farm installation can be done through PowerShell using the SharePoint PS-Snapin.
While making every configuration for a SharePoint farm is out of scope for this article, here are the PowerShell commands that will make your SharePoint farm initialization easy and uniform:
New-SPConfigurationDatabase actually creates the farm by turning on the Configuration Database. If SharePoint was creating the farm through the wizard instead of PowerShell, the database would be called SharePoint_Config.
However, by using this command you will be able to change the database name so that it will be consistent with the rest of the naming structure. This also makes it very easy to distinguish between different farms that are using the same SQL server, for instance, a “SP2013_SharePoint_Config” and a “SP2010_SharePoint_Config”.
You’ll need to pass a few parameters into the command. You have to specify the database instance location, and you’ll have to name the Configuration Database and the Central Admin Content database. Finally, you have to specify a farm passphrase for the farm and provide credentials of the Farm Administrator account.
This is an example that you can use to create the SharePoint Farm databases:
New-SPConfigurationDatabase -DatabaseServer $DBAlias `
-DatabaseName “$Prefix\_SharePoint_Config” `
-AdministrationContentDatabaseName “$Prefix\_Admin_Content” `
-Passphrase $Passphrase `
Next, you’ll need to set up a Central Administration site. This is a simple configuration step — all you need to do is set a port for the Central Administration site. However, if you’re going to use Kerberos authentication instead of NTLM, you’ll need to specify it with the -WindowsAuthProvider parameter. You can also specify NTLM as the Authentication Provider, but you don’t need to because omitting it is the same as specifying NTLM.
New-SPCentralAdministration -Port $CentralAdmin -WindowsAuthProvider "NTLM"
Extras to Setup
- Install all of the SharePoint Help.
- You’ll want to make sure that all of your resources, including files, folders, and registry keys are ready to be controlled by security policies.
- Install and provision services, service proxies, and service instances.
- Copies shared application data to existing Web Applications.
- Turn on all of the SharePoint features. Install-SPFeature outputs a list of the features that are installed. If you’re adding this into a script and doing more for your SharePoint configuration (such as scripting the setup and configuration of a Search service,) you could easily save it into a $Features variable and output it later in the script as things are finishing up.
Install-SPFeature -AllExistingFeatures -Force
Other PowerShell Options and Commands
Now that you’ve gotten the farm set up and the first databases configured, there are some other commands that you should consider.
Create a New Web Application
New-SPWebApplication: The first part of creating a Web Application with PowerShell is to create the web application and application pool. You have to specify an application pool name. If the application pool doesn’t exist yet, you’ll have to specify an account to run the application pool as by using the Get-SPManagedAccount cmdlet. You’ll also have to name the web application.
–DatabaseName: You should also take this opportunity to specify the name of the content database used by taking advantage of the optional –DatabaseName parameter. If you omit this parameter, it will be set to the default WSS_Content_<GUID>, which would look much better as SP2013_User_Profile_Content than WSS_Content_HugeRandomStringOfCharacters.
Other parameters that you may be looking for are there, too: You can set the authentication method (again, NTLM is used if this isn’t specified), the port, the host header, the path to the virtual directory and the load balanced Url.
Absolutely every aspect of SharePoint administration can be performed with PowerShell. In some cases, you may find it easier to complete these tasks from with Central Administration. However, in most cases using PowerShell provides the most ability to administer SharePoint in consistent, reliable, and repeatable methods. Using PowerShell is also the way to configure your SharePoint farm so that the databases are consistent and easy to read.
So, if you’ve been taking the easy road and working your way through the SharePoint Products Configuration Wizard to install your SharePoint farm — stop! Roll up your sleeves, take a few extra minutes to figure out the PowerShell commands and setup your farm exactly the way you want it.