UX Empowered SharePoint Site Creation

Anyone working with a client to either migrate to or stand up a new install of SharePoint has faced the need to build out a logical architecture for the new site. If you are lucky enough to work with a professional user experience team you no doubt benefit from several of the practices including but not limited to card sorting exercises, user interviews, mockups and information architecture diagrams. This post specifically talks about consuming the information architecture asset built out by our UX team in the context of PowerShell.

Information Architecture Example

What can be done is to transpose the IA document into a CSV file. Using Import-Csv we can iterate over the lines in the file and branch on a flag for actions like creating a site collection versus a sub site. Further, we can plan for scalability by creating separate content databases per new site collection right out the gate using the New-SPContentDatabase and then New-SPSite.

Alternately we have the need to create all our sub webs using the New-SPWeb. As we loop we have the chance to configure various site settings based on our requirements. I used the following settings in a recent migration project: AddToQuickLaunch, UniquePermissions, AddToTopNav, UseParentTopNav, IncludeSubSitesInNavigation.

$snapin = Get-PSSnapin|Where-Object{$_.Name -eq 'Microsoft.SharePoint.Powershell'}
if ($snapin -eq $null)
Write-Host "Loading SharePoint Powershell Snap-in"
Add-PSSnapin "Microsoft.SharePoint.Powershell"

# Server properties:
$DBServer = "your\host"
$WebApplication = "http://yoursite"
$port = ":80"
$sitecsv = Import-Csv("C:\your\directory\SiteStructure1.csv")

foreach($s in $sitecsv)
$siteurl = $WebApplication + $port + $s.SiteUrl
Write-Host( "Processing:" + $siteurl )

# Setting this value to 1 in the CSV file means this is a site collection which will need it's own content database.
# Otherwise the object is a subsite and as such will live inside an existing site collection database.
if( $s.IsSiteCol -eq 1 )
$DBName = $s.DBName

# Warning - this will remove the Site Collection DB - make sure this is the action you want to take on subsequent runs.
Write-Host( "Removing: " + $siteurl )
Remove-SPSite -identity $siteurl -GradualDelete -Confirm:$False

Write-Host( "Removing Database: " + $DBName )
Get-SPContentDatabase | Where { $_.Name -eq $DBName } | Remove-SPContentDatabase

Write-Host( "Adding: " + $siteurl + " DBName: " + $DBName)
if ($DBName.Length -gt 0)
New-SPContentDatabase -Name $DBName -DataBaseServer $DBServer -WebApplication $WebApplication
New-SPSite -Url $siteurl -OwnerAlias $s.SitePrimaryOwner -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -SecondaryOwnerAlias $s.SiteSecondaryOwner -Template $s.SiteTemplate -ContentDatabase $DBName
New-SPSite -Url $siteurl -OwnerAlias $s.SitePrimaryOwner -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -SecondaryOwnerAlias $s.SiteSecondaryOwner -Template $s.SiteTemplate
# This is a good place to activate features for the site collection in the event you are not using a feature staple or site collection level event receiver.
# Enable-SPFeature -identity "DocumentSet" -url $siteurl
$web = Get-SPWeb $siteurl
if (($web -ne $null) -and ($web -ne "")) {
Continue; #SKIP THIS SITE - it already exists

# The following are values that may end up being different depending on what your project requirements.
$AddToQuickLaunch = if( $s.AddToQuickLaunch -eq 0 ){ $False } else { $True }
$UniquePermissions = if( $s.UniquePermissions -eq 0 ){ $False } else { $True }
$AddToTopNav = if( $s.AddToTopNav -eq 0 ){ $False } else { $True }
$UseParentTopNav = if( $s.UseParentTopNav -eq 0 ){ $False } else { $True }
$IncludeSubSitesInNavigation = if( $s.IncludeSubSitesInNavigation -eq 0 ){ "False" } else { "True" }

# Adding our new site and setting up subsite navigation
Write-Host( "Adding:" + $siteurl )
New-SPWeb -Url $siteurl -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -Template $s.SiteTemplate -UniquePermissions:$UniquePermissions;
$web = Get-SPWeb $siteurl
if (($web -ne $null) -and ($web -ne "")) {
$web.AllProperties["__IncludeSubSitesInNavigation"] = $IncludeSubSitesInNavigation

Lastly, since we are touching every site object you may see some benefit to activate both site collection and site scope features using our script. Of course you may reasonably choose to move these actions off to either a feature staple, feautre or web scope event receiver.

So with just a little PowerShell you can save your team some time by automating the site collection and subsite creation process. What our script does not do is to remove the site collection and subsites. This could very easily be coded but you can also, simply, go to Central Administration to remove the site collection and then rerun the script. Cases may include instances where you are doing some heavy web part development with components scattered throughout the site collection. Without a feature deactivation event receiver to do the cleanup page by page for us it would be far simpler to just nuke and recreate the site structure and start from scratch. Another use case for this script, as mentioned before, incudes deploying the same structure to multiple dev and test hosts will save your architect the process of making copies of the various content databases and moving them to other hosts.

In conclusion using PowerShell can serve as a great tool for automating the implementation of the information architecture asset built out by our UX team. Thus providing both a repeatable process and high fidelity across the design and development life-cycle.

The original source of this thought process comes from this post.

Tagged with: , ,

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.