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.

<br />
$snapin = Get-PSSnapin|Where-Object{$_.Name -eq 'Microsoft.SharePoint.Powershell'}<br />
if ($snapin -eq $null)<br />
{<br />
Write-Host &quot;Loading SharePoint Powershell Snap-in&quot;<br />
Add-PSSnapin &quot;Microsoft.SharePoint.Powershell&quot;<br />
}</p>
<p># Server properties:<br />
$DBServer = &quot;your\host&quot;<br />
$WebApplication = &quot;http://yoursite&quot;<br />
$port = &quot;:80&quot;<br />
$sitecsv = Import-Csv(&quot;C:\your\directory\SiteStructure1.csv&quot;)</p>
<p>foreach($s in $sitecsv)<br />
{<br />
$siteurl = $WebApplication + $port + $s.SiteUrl<br />
Write-Host( &quot;Processing:&quot; + $siteurl )</p>
<p># Setting this value to 1 in the CSV file means this is a site collection which will need it's own content database.<br />
# Otherwise the object is a subsite and as such will live inside an existing site collection database.<br />
if( $s.IsSiteCol -eq 1 )<br />
{<br />
$DBName = $s.DBName</p>
<p># Warning - this will remove the Site Collection DB - make sure this is the action you want to take on subsequent runs.<br />
Write-Host( &quot;Removing: &quot; + $siteurl )<br />
Remove-SPSite -identity $siteurl -GradualDelete -Confirm:$False</p>
<p>Write-Host( &quot;Removing Database: &quot; + $DBName )<br />
Get-SPContentDatabase | Where { $_.Name -eq $DBName } | Remove-SPContentDatabase</p>
<p>Write-Host( &quot;Adding: &quot; + $siteurl + &quot; DBName: &quot; + $DBName)<br />
if ($DBName.Length -gt 0)<br />
{<br />
New-SPContentDatabase -Name $DBName -DataBaseServer $DBServer -WebApplication $WebApplication<br />
New-SPSite -Url $siteurl -OwnerAlias $s.SitePrimaryOwner -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -SecondaryOwnerAlias $s.SiteSecondaryOwner -Template $s.SiteTemplate -ContentDatabase $DBName<br />
}<br />
else<br />
{<br />
New-SPSite -Url $siteurl -OwnerAlias $s.SitePrimaryOwner -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -SecondaryOwnerAlias $s.SiteSecondaryOwner -Template $s.SiteTemplate<br />
}<br />
# 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.<br />
# Enable-SPFeature -identity &quot;DocumentSet&quot; -url $siteurl<br />
}<br />
else<br />
{<br />
$web = Get-SPWeb $siteurl<br />
if (($web -ne $null) -and ($web -ne &quot;&quot;)) {<br />
Continue; #SKIP THIS SITE - it already exists<br />
}</p>
<p># The following are values that may end up being different depending on what your project requirements.<br />
$AddToQuickLaunch = if( $s.AddToQuickLaunch -eq 0 ){ $False } else { $True }<br />
$UniquePermissions = if( $s.UniquePermissions -eq 0 ){ $False } else { $True }<br />
$AddToTopNav = if( $s.AddToTopNav -eq 0 ){ $False } else { $True }<br />
$UseParentTopNav = if( $s.UseParentTopNav -eq 0 ){ $False } else { $True }<br />
$IncludeSubSitesInNavigation = if( $s.IncludeSubSitesInNavigation -eq 0 ){ &quot;False&quot; } else { &quot;True&quot; }</p>
<p># Adding our new site and setting up subsite navigation<br />
Write-Host( &quot;Adding:&quot; + $siteurl )<br />
New-SPWeb -Url $siteurl -Confirm:$False -Description $s.SiteDescription -Name $s.SiteName -Template $s.SiteTemplate -UniquePermissions:$UniquePermissions;<br />
$web = Get-SPWeb $siteurl<br />
if (($web -ne $null) -and ($web -ne &quot;&quot;)) {<br />
$web.AllProperties[&quot;__IncludeSubSitesInNavigation&quot;] = $IncludeSubSitesInNavigation<br />
$web.Update()<br />
$web.Dispose()<br />
}<br />
}<br />
}</p>
<p>

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.