How to Create SharePoint 2016 Farm using PowerShell?

SharePoint 2016 is a powerful platform for creating and managing collaborative websites and business applications. Creating a SharePoint farm can be a complex task, but PowerShell can simplify the process significantly. This blog post will show you how to create a SharePoint 2016 farm using PowerShell. This can be useful if you want to automate your SharePoint farm’s creation.

Creating a SharePoint 2016 farm using PowerShell is almost the same as in its previous version. In SharePoint 2016, there is an additional parameter -LocalServerRole added as SharePoint 2016 introduced MinRoles.

Pre-Requisites:

You need to ensure that you have the necessary hardware and software components in place, such as a server operating system, SQL Server, and SharePoint 2016 installation files.

  • SQL Server is already installed and ready to use.
  • You have created a Farm account for SharePoint 2016.
  • You have logged in to the server (Setup account) with Administrator access on all SharePoint servers and DB_Creator, and Security_Admin Server roles in SQL Server.

Step 1: Install SharePoint 2016 prerequisites and binaries to each server in your proposed SharePoint 2016 farm

install sharepoint 2016 farm using powershell

On completing the installation, Uncheck “Run the SharePoint Products Configuration Wizard now” and close the wizard.

create new sharepoint 2016 farm with Powershell

Step 2: PowerShell Script to Create SharePoint 2016 Farm:

Save the below script as “Create-Farm.ps1” or something like that, and change the configuration settings parameters as per your environment. Open SharePoint 2016 Management Shell as Administrator, and run the script. You’ll see the “The local farm is not accessible. Cmdlets with FeatureDependencyId are not registered.” error for the first time, which is quite normal since we have not created the farm yet! Proceed to run the script.

#Configuration Settings 
$DatabaseServer = "SP16-SQL"
$ConfigDatabase = "Intranet_Farm_Config"
$AdminContentDB = "Intranet_Farm_Content_Admin"
$Passphrase = "2FJlsXghFsas5vdJJKEXXwWF"
$FarmAccountName = "Crescent\Sp2016admin"
$ServerRole="SingleServerFarm"

#Get the Farm Account Credentials
$FarmAccount = Get-Credential $FarmAccountName
$Passphrase = (ConvertTo-SecureString $Passphrase -AsPlainText -force)
  
#Create SharePoint Farm
Write-Host "Creating Configuration Database and Central Admin Content Database..."
New-SPConfigurationDatabase -DatabaseServer $DatabaseServer -DatabaseName $ConfigDatabase -AdministrationContentDatabaseName $AdminContentDB -Passphrase $Passphrase -FarmCredentials $FarmAccount -LocalServerRole $ServerRole

$Farm = Get-SPFarm -ErrorAction SilentlyContinue -ErrorVariable err  
if ($Farm -ne $null) 
{
Write-Host "Installing SharePoint Resources..."
Initialize-SPResourceSecurity
 
Write-Host "Installing Farm Services ..."
Install-SPService
 
Write-Host "Installing SharePoint Features..."
Install-SPFeature -AllExistingFeatures
 
Write-Host "Creating Central Administration..."              
New-SPCentralAdministration -Port 2016 -WindowsAuthProvider NTLM
  
Write-Host "Installing Help..."
Install-SPHelpCollection -All  
 
Write-Host "Installing Application Content..."
Install-SPApplicationContent
  
Write-Host "SharePoint 2016 Farm Created Successfully!"
} 

Once the script is completed successfully, You’ll see the “Farm created successfully” message. Here I’ve used “SingleServer” as MinRole, and you can adjust it based on your requirement.

Alternatively, You can create a SharePoint Farm (Run script till line#15) and then Run Products configuration wizard to complete the rest of the steps in farm creation.

Add Additional Servers to the SharePoint 2016 Farm:
Once you are done with the creation of the SharePoint 2016 farm from the first server, You can connect the rest of the servers to the farm, either using the SharePoint products configuration wizard or with PowerShell.

Open the SharePoint products configuration wizard and choose “Connect to an existing server farm” and run through the wizard! Select the server MinRole as per your topology.

powershell script to create sharepoint 2016 farm

Join Additional Server to the SharePoint 2016 farm using PowerShell:
If you prefer the PowerShell way to add another server to the farm, use this PowerShell script.  

$ServerRole="Application"
#"Custom","WebFrontEnd","Application","DistributedCache","SingleServerFarm","Search","ApplicationWithSearch","WebFrontEndWithDistributedCache"

Connect-SPConfigurationDatabase -DatabaseServer $DBServer -DatabaseName $DBName -PassPhrase $Passphrase -LocalServerRole $ServerRole
 
Write-Host "Installing SharePoint Resources..."
Initialize-SPResourceSecurity
 
Write-Host "Installing Farm Services ..."
Install-SPService
 
Write-Host "Installing SharePoint Features..."
Install-SPFeature -AllExistingFeatures
 
Write-Host "Installing Help..."
Install-SPHelpCollection -All  
 
Write-Host "Installing Application Content..."
Install-SPApplicationContent
  
Write-Host "Joined the Server to Farm Successfully!"
If you don’t want the server to host Distributed cache, use the parameter: -SkipRegisterAsDistributedCacheHost and the end!

Related post: How to Create SharePoint 2013 farm using PowerShell?

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

12 thoughts on “How to Create SharePoint 2016 Farm using PowerShell?

  • Hi Salaudeen,
    Need one help, I hv installed SP2019 in minrole with each one server holding Front-end, App, Cache & Serach with SQL as another external server but all are in same network & IP range.
    It is freshly installed but for some reason on the Search Server getting this below error event in every 5 min. Any help will be great.
    Event ID: 2159
    Task Category: Unified Logging Service
    Error message : Event 62 (Search) of severity ‘Error’ occurred 126 more time(s) and was suppressed in the event log

    Thanks, MA

    Reply
  • Hi Salaudeen – 1) Is this the same for installing SharePoint 2019 & 2) Do you run the script from the folder containing the SharePoint setup/binaries files?

    Reply
  • Hello,
    I have a question: does the farm config steps’ order matter ? I mean, you followed the following order in your script :

    Initialize-SPResourceSecurity > Install-SPService > Install-SPFeature > New-SPCentralAdministration > Install-SPHelpCollection > Install-SPApplicationContent

    But I found other articles/scripts doing the same but with different order as follows :

    Install-SPHelpCollection > Initialize-SPResourceSecurity > Install-SPService > Install-SPFeature > New-SPCentralAdministration > Install-SPApplicationContent

    so ?

    Reply
  • Thanks for your useful post. I may did a mistake running your script… I was logged in as SP_Admin (because the only local Admin and RDP user for this machine) and ran your script. I named the user SP_Farm as Farm Account Name. The config itself was successfull and I can access the Central Administration partyl with the SP_Farm account. But I cannot do the most settings. Either they are greyed out or I get “Sorry, this page was not shared with you yet”. The SP_Admin user can do everything I want…
    I see the SP_Farm account as member in farm administrators group. Where’s the fault? I don’t get it…

    Reply
    • Disable Internet Explorer Enhanced Security and Add a Full control Policy to your SP_Admin Account!

      Reply
  • I ran the script and get cannot bind parameter ‘passphrase’ cannot convert the value of type system.string to type system secure string? the under Get-farm a positional parameter cannot be found that accepts argument if?

    Reply
  • Tnx alot for useful post

    Reply
  • I don’t find the Custom Ribbon on the top in the Central Admin screen ? what could be the issue?Please advise

    Reply
  • Thank you so much for sharing this script. Its pretty clean and neat, I’m able to pickup although I’m new to SharePoint. Kudos.
    Sekar

    Reply
  • Great Work you do man. Very much appreciate it 🙂

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *