SharePoint farm configurations are notoriously difficult in not only documenting accurately but also migrating those configurations to a new SharePoint farm. Did you know you can use PowerShell DSC (Desired State Configuration) and a community PowerShell module to make it easier? Read on!
Commercial tools and utilities help, but each tool has its pluses and minuses and some of them are not effective and often buggy. Additionally, the tools can be expensive and come with a high learning curve.
Table of Contents
SharePointDSC.Reverse is a script developed by Nik Charlebois that uses SharePoint DSC resources to gather detailed information about the farm and outputs into a configuration file that can be consumed by PowerShell DSC and SharePointDSC resources.
The resulting PowerShell DSC configuration files can be used to create a near perfect copy of the farm to replicate in the new environment or can be used as a template for Azure automation.
SharePointDsc.Reverse currently supports SharePoint Server 2013/ 2016 and soon SharePoint 2019, running on Windows Server 2008 R2, Windows Server 2012 or Windows Server 2012 R2 or higher.
There are a few prerequisites before running the script.
- Windows PowerShell v5.1
Once you have the prerequisites, log into your SharePoint Central Administration server and open a PowerShell session as administrator. The SharePointDSC reverse script is installed with a similar command but using a script instead of module. To install the SharePoint Reverse script, use
Now that we have all the necessary modules installed, it’s fairly easy to use. To start the process, enter
As the script runs, it asks for the credentials for the various managed accounts. Using the DSC resource provided by SharePointDSC, the script performs a detailed scan of the farm, gathering all the settings and configurations.
For a large farm, this will take several minutes to complete. Once it’s complete, It prompts for a directory to save the results. the resulting files can be consumed by SharePointDSC.
To validate the configuration, compile the spfarmconfig.ps1 file to create the .mof resources.
The resulting files from SharePointDSC.Reverse can be used to duplicate the SharePoint farm in different environments, on-premises or in the cloud.
The configuration file, the error log, and the environment data file, all contain detailed configuration settings of the farm. Custom solutions (.wsp files) are copied into the directory as well.
Duplicating the SharePoint farm
The SPFarmConfig.ps1 file can also be uploaded to Azure Automation to duplicate farm configurations for your Azure based SharePoint farm. To duplicate the SharePoint farm in a new environment, apply the configuration to the farm by starting the DSC configuration.
Start-DscConfiguration .\SPFarmConfig -Force -Wait -Verbose
In a multi-node farm, the configurationdata.ps1 file already has the node names, roles, and services that are running on each server in the farm. The file is formatted very similar to JSON and editing this file for the new environment can easily be completed using Visual Studio Code.
The spfarmconfig.ps1 file has the detailed farm configuration and also lists products installed and version numbers. It will also have details about each web application, site collection, and farms settings. Patches applied and version numbers of products installed are also displayed.
One additional benefit of these files is that they can be part of a disaster recovery plan. Restoring the farm from a complete loss can now be accomplished in hours instead of days.
You’ve learned that using PowerShell DSC, you can manage SharePoint environments just like any other infrastructure item. Using a community module called SharePointDsc.Reverse allows you to automate duplicating SharePoint farms!