Provision a new site collection with 1-to-1 Mappings using PowerShell

Products: Nintex Workflow 2013, Nintex Workflow 2010

This PowerShell script will do the following:

  • Create a new SharePoint Content Database
  • Create a new SharePoint Site Collection and assign it to the newly created SharePoint Content Database
  • Set the SharePoint Content Database to not allow any new Site Collections to be associated with it
  • Provision a new Nintex Content Database
  • Create a 1-to-1 Mapping with the SharePoint Content Database and the Nintex Content Database
  • Activate Nintex Workflow and Forms Site Collection Features
  • Activate Nintex Workflow SubSite Features

#Load assemblies
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue  
$assemblies = "Nintex.Workflow.Administration", "System.Data.SqlClient.SqlConnectionStringBuilder"
foreach($assembly in $assemblies)  
#Set variables
$hostname = "" #Set web application hostname
$sitename = "teamsite" #Set site name
$managedpath = "sites" #Set managed path
$siteurl = "$($hostname)/$($managedpath)/$($sitename)"
$siteTemplate = $(Get-SPWebTemplate | WHERE {$_.Title -eq 'Team Site' -and $_.CompatibilityLevel -eq 15}) #Set to Teamsite by default
$owner = "siteowner" #Set siteowner
$databasename = "SPContentDB_$(sitename)" #Set SharePoint content database name
$databaseserver = "SERVER\SHAREPOINT" #Set SQL database server
$NintexDBName = "NW2013DB_$($sitename)" #Set Nintex content database name
$connectionstring = "Server=$($databaseserver); Database=$($NintexDBName); Integrated Security = true;"
#Provision site collection and SharePoint content database.
New-SPContentDatabase -Name $databasename -DatabaseServer $databaseserver -WebApplication $hostname  
New-SPSite -URL $siteurl -OwnerAlias $owner -ContentDatabase $databasename -Template $siteTemplate  
Get-SPContentDatabase -Site $siteurl | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0  
#Provision Nintex content database
$dbattacher = New-Object -TypeName Nintex.Workflow.Administration.DatabaseAttacher -ArgumentList @($connectionstring,[Nintex.Workflow.Administration.DatabaseAttachValidationMode]::PerformValidation)
$dbattacher.AttachOptions.ProvideAllWebApplicationsAccess = $true
$dbattacher.AttachOptions.CreateNewDatabase = $true
$dbattacher.AttachOptions.IncludeStorageRecordStep = $true
$result = $dbattacher.Attach()
$configdb = [Nintex.Workflow.Administration.ConfigurationDatabase]::GetConfigurationDatabase()
#Create 1-to-1 mapping
$newcontentdb = $configdb.ContentDatabases.FindByDatabaseAndServerName($databaseserver, $NintexDBName)
$newdbmapping = New-Object -TypeName Nintex.Workflow.ContentDbMapping
$newdbmapping.SPContentDbId = $(Get-SPDatabase | Where {$_.Name -eq $databasename}).Id
$newdbmapping.NWContentDbId = $newcontentdb.DatabaseId
#Activate Site Collection Features
foreach($id in @('eb657559-be37-4b91-a369-1c201183c779', '0561d315-d5db-4736-929e-26da142812c5', '716f0ee9-e2b0-41f0-a73c-47ed73f135de','202afc3c-7384-4700-978d-6da3d3cce192', 'ac8addc7-7252-4136-8dcb-9887a277ae2c', '53164b55-e60f-4bed-b582-a87da32b92f1', '23fce797-ac15-4451-b8da-cf8ac6de6912', '54668547-c03f-4bb5-aaab-d9568ebaf9c9', '80bf3218-7353-11df-af9f-058bdfd72085'))  
$(Get-SPFeature -Identity $id) | Enable-SPFeature -Url $siteurl
#Activate Subsite Features
foreach($id in @('9bf7bf98-5660-498a-9399-bc656a61ed5d', '2fb9d5df-2fb5-403d-b155-535c256be1dc'))  
$(Get-SPFeature -Identity $id) | Enable-SPFeature -Url $siteurl

To use the script do the following:

  • Ensure you are running the PowerShell console as a SharePoint Administrative account.

  • Configure the variables in the script to the application.