Deploy SharePoint Site Columns with One PowerShell command

Recently, I had to come up with a new way to deploy our email site columns for our OnePlaceMail product as the old way (sandboxed solutions) were no longer supported.

I had to make it simple for users and come up with a way that would allow me to easily modify/add site columns in the future.

I decided to use the SharePoint PnP PowerShell Cmdlets and GitHub to host the solution so users could simply run 1 PowerShell command, enter a site collection url and the site columns would be deployed to their site collection.

The process is as follows:

  • Execute PowerShell command to run PowerShell script (ps1) hosted in GitHub.
  • User is prompted for the Site Collection Url, enter url and hit return
  • Provisioning Xml template which details all the Site Columns settings is downloaded to the user’s temp folder on their machine.
  • PnP provisioning command is executed to apply provisioning template to the Site Collection and therefore provisioning the Site Columns.

If in the future if I need to remove/add/modify any Site Columns I simply edit the provisioning xml:

provisioningxml

Below details the full PowerShell script and the GitHub repo can be found here: https://github.com/OnePlaceSolutions/EmailColumnsPnP

<#
        This script prompts you to install the SharePoint PnP commands. Hit enter for SharePoint Online,
        6 for SharePoint 2016,3 for SharePoint 2013
        The script then prompts for the site collectiuon url you wish to install the Email Columns to
        and then applies the email columns template to this site collection        
#>

try {    
    Set-ExecutionPolicy Bypass -Scope Process 
    #Prompt for SharePoint Url     
    $SharePointUrl = Read-Host -Prompt 'Enter your SharePoint Site Collection Url to install OnePlace Solutions Email Columns to'
    Connect-pnpOnline -url $SharePointUrl
    #Download xml provisioning template
    $WebClient = New-Object System.Net.WebClient   
    $Url = "https://raw.githubusercontent.com/OnePlaceSolutions/EmailColumnsPnP/master/email-columns.xml"    
    $Path = "$env:temp\email-columns.xml"

    Write-Host "Downloading provisioning xml template:" $Path -ForegroundColor Green 
    $WebClient.DownloadFile( $Url, $Path )   
    #Apply xml provisioning template to SharePoint
    Write-Host "Applying email columns template to SharePoint:" $SharePointUrl -ForegroundColor Green 
    Apply-PnPProvisioningTemplate -path $Path
   
}
catch {
    Write-Host $error[0].Message
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s