Share via


Configure a SharePoint Server 2010 or 2013 farm using PowerShell

Just like the PSConfig command, we can also use PowerShell to configure the SharePoint farm from scratch.

Below is a set of PSConfig commands and their equivalent cmdlet in PowerShell.

PSConfig Command PowerShell Cmdlet
configdb -create New-SPConfigurationDatabase
configdb -connect Connect-SPConfigurationDatabase
helpcollections -installall Install-SPHelpCollection
secureresources Initialize-SPResourceSecurity
services -install Install-SPService
installfeatures Install-SPFeature (provide the -AllExistingFeatures parameter)
adminvs -provision New-SPCentralAdministration
applicationcontent -install Install-SPApplicationContent

During the SharePoint Installation, make sure you choose “Server Farm” and then “Complete” install. This will allow you to create a SharePoint farm rather than a standalone server.

After the install completes, the setup program will ask you if you want to run the SharePoint Technologies Configuration Wizard (default is checked). Uncheck the box to NOT run the wizard.

Under the Start Menu, browse to Microsoft SharePoint 2010 Products, Right-click on SharePoint 2010 Management Shell and choose 'Run as administrator'

Note: Since we have not created a farm yet, the shell will load with an error that the local farm is not accessible. This is expected. 

The Cmdlets

There are seven cmdlets that you will need to provision your farm so that you can access it correctly. The cmdlets are listed below along with their descriptions provided by the Get-Help cmdlet.

New-SPConfigurationDatabase*

The New-SPConfigurationDatabase cmdlet creates a new configuration database on the specified database server. This is the central database for a new SharePoint farm.

* Create a new configuration database and central admin content database.

Note: One of the main reason why we use this method as against the configuration wizard UI is because we can specify the names for the central admin database.

New-SPConfigurationDatabase -DatabaseName <ConfigDBname> -DatabaseServer <DBservername> -FarmCredentials (Get-Credential <farmaccount) -Passphrase <Passprase> -AdministrationContentDatabaseName <AdminDBname>

Note: As you can see, we are having PowerShell prompt us for the farm credentials rather than hard coding it. You can also do this with the passphrase by accessing the “Password” property of the of the credential object: (Get-Credential).Password

After the operation completes, you can confirm that the server has been added to a farm, by reloading the PowerShell window. Close the shell and repeat the “Run as administrator” step followed earlier. It should load without any warning message(s).

Install-SPHelpCollection*

The Install-SPHelpCollection cmdlet installs the Help site collection files for SharePoint 2010 Products in the current farm. Use the LiteralPath parameter to install specific custom Help collection files. If the LiteralPath parameter is not specified, all available help in the Help site collection is installed and existing Help collection files are overwritten.

* Install the help files:

Install-SPHelpCollection –All

Initialize-SPResourceSecurity*

The Initialize-SPResourceSecurity cmdlet enforces resource security on the local server. This cmdlet enforces security for all resources, including files, folders, and registry keys.

* Secure the files and registry entries (SecureResources in PSConfig):

Initialize-SPResourceSecurity

Install-SPService
**
**The Install-SPService cmdlet installs and optionally provisions services on a farm. This cmdlet installs all services, service instances, and service proxies specified in the registry on the local server computer. Use this cmdlet in a script that you build to install and deploy a SharePoint farm or to install a custom developed service.

* Install and provision the services on to the farm

Install-SPService

Note: The above command is for Server farm installations only. For standalone servers, run Install-SPService –Provision.

Install-SPFeature*

The Install-SPFeature cmdlet installs a specific SPFeature object by providing in the Identity parameter the relative path from the folder “%Program Files%\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\FEATURES\ to the feature. The SharePoint Feature’s files must already be put in the proper directory, either manually or by using a solution installer. If the AllExistingFeatures parameter is provided, the file system is scanned and any new features are installed. This is generally only used during deployment and upgrade.

* Install the features on the server

Install-SPFeature –AllExistingFeatures

New-SPCentralAdministration*
**
**The New-SPCentralAdministration cmdlet creates a new Central Administration Web application and starts the central administration service on the local machine. Central Administration is available only on computers where this service runs.

* Provisions the central admin web application which will also link it with the admin content database created earlier

New-SPCentralAdministration -Port 2010 -WindowsAuthProvider "NTLM"

Install-SPApplicationContent*

The Install-SPApplicationContent cmdlet copies shared application data to existing Web application folders. This cmdlet does not take any parameters.

* Install all of the application content

Install-SPApplicationContent

**
The Script
**

#this can be used for SharePoint 2010 and SharePoint 2013

$DatabaseServer = "DBservername";
$FarmName = "SP2013";
$ConfigDB = $FarmName+"_ConfigDB";
$AdminContentDB = $FarmName+"_CentralAdminContent";
$Passphrase = convertto-securestring "Password123" -asplaintext -force;
$Port = "2013";
$Authentication = "NTLM";
$FarmAccount = "Sp2013\SPFarm"

 

New-SPConfigurationDatabase -DatabaseName $ConfigDB -DatabaseServer $DatabaseServer -FarmCredentials (Get-Credential $farmAccount) -Passphrase $Passphrase -AdministrationContentDatabaseName $AdminContentDB

Install-SPHelpCollection -All
"Installed Help Collection"

Initialize-SPResourceSecurity
"Initialized SP Resource Security"

Install-SPService
"Installed SP service"

Install-SPFeature -AllExistingFeatures
"Installed SP Feature"

New-SPCentralAdministration -Port $Port
"Created Central Administration Site"

Install-SPApplicationContent
"Installed Application Content"