aaron.labiosa@nintex.com

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

Blog Post created by aaron.labiosa@nintex.com Champion on Feb 18, 2016

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

 

PowerShell Script
  1. #Load assemblies
  2. Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
  3. $assemblies = "Nintex.Workflow.Administration", "System.Data.SqlClient.SqlConnectionStringBuilder"
  4. foreach($assembly in $assemblies)
  5. {
  6.     [void][System.Reflection.Assembly]::LoadWithPartialName($assembly)
  7. }
  8. #Set variables
  9. $hostname = "http://contoso.com" #Set web application hostname
  10. $sitename = "teamsite" #Set site name
  11. $managedpath = "sites" #Set managed path
  12. $siteurl = "$($hostname)/$($managedpath)/$($sitename)"
  13. $siteTemplate = $(Get-SPWebTemplate | WHERE {$_.Title -eq 'Team Site' -and $_.CompatibilityLevel -eq 15}) #Set to Teamsite by default
  14. $owner = "siteowner" #Set siteowner
  15. $databasename = "SPContentDB_$(sitename)" #Set SharePoint content database name
  16. $databaseserver = "SERVER\SHAREPOINT" #Set SQL database server
  17. $NintexDBName = "NW2013DB_$($sitename)" #Set Nintex content database name
  18. $connectionstring = "Server=$($databaseserver); Database=$($NintexDBName); Integrated Security = true;"
  19. #Provision site collection and SharePoint content database.
  20. New-SPContentDatabase -Name $databasename -DatabaseServer $databaseserver -WebApplication $hostname
  21. New-SPSite -URL $siteurl  -OwnerAlias $owner -ContentDatabase $databasename -Template $siteTemplate
  22. Get-SPContentDatabase -Site $siteurl | Set-SPContentDatabase -MaxSiteCount 1 -WarningSiteCount 0
  23. #Provision Nintex content database
  24. $dbattacher = New-Object -TypeName Nintex.Workflow.Administration.DatabaseAttacher -ArgumentList @($connectionstring,[Nintex.Workflow.Administration.DatabaseAttachValidationMode]::PerformValidation)
  25. $dbattacher.AttachOptions.ProvideAllWebApplicationsAccess = $true
  26. $dbattacher.AttachOptions.CreateNewDatabase = $true
  27. $dbattacher.AttachOptions.IncludeStorageRecordStep = $true
  28. $result = $dbattacher.Attach()
  29. $configdb = [Nintex.Workflow.Administration.ConfigurationDatabase]::GetConfigurationDatabase()
  30. #Create 1-to-1 mapping
  31. $newcontentdb = $configdb.ContentDatabases.FindByDatabaseAndServerName($databaseserver, $NintexDBName)
  32. $newdbmapping = New-Object -TypeName Nintex.Workflow.ContentDbMapping
  33. $newdbmapping.SPContentDbId = $(Get-SPDatabase | Where {$_.Name -eq $databasename}).Id
  34. $newdbmapping.NWContentDbId = $newcontentdb.DatabaseId
  35. $newdbmapping.CreateOrUpdate()
  36. #Activate Site Collection Features
  37. 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'))
  38. {
  39. $(Get-SPFeature -Identity $id) | Enable-SPFeature -Url $siteurl
  40. }
  41. #Activate Subsite Features
  42. foreach($id in @('9bf7bf98-5660-498a-9399-bc656a61ed5d', '2fb9d5df-2fb5-403d-b155-535c256be1dc'))
  43. {
  44. $(Get-SPFeature -Identity $id) | Enable-SPFeature -Url $siteurl
  45. }

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.

Outcomes