Provision multiple SharePoint Online site collections with PnP PowerShell

This blog post follows on from my previous blog post on basic SharePoint site collection provisioning in Office 365: https://colinjwood.wordpress.com/2017/12/14/create-a-sharepoint-site-collection-in-an-office-365-tenant-with-pnp-powershell/

In this post I will go through how you can provision multiple site collections in an Office 365 tenant using a csv file which specifies configuration information about each site collection:

  • Url
  • Site Owner
  • Template
  • Timezone
  • Title

The source code for this post is in my GitHub repo at: https://github.com/colinjwood/CodeCobra/tree/master/CSVProvisioning

The script is here: https://github.com/colinjwood/CodeCobra/blob/master/CSVProvisioning/createSiteCollectionsFromCSV.ps1

I have included an example csv file in the repo that the script uses. It needs to be located in ‘C:\\temp’ on local machine running the script. This step could also be automated so that the csv file is downloaded from GitHub to the temp folder on the local machine, then used by the script for site collection provisioning. I use this technique in one of my other GitHub repos here at OnePlace Solutions to provision Site Columns in SharePoint. The provisioning xml is downloaded then used by the PowerShell script : https://github.com/OnePlaceSolutions/EmailColumnsPnP/blob/master/installEmailColumns.ps1

image

To run the SharePoint site collection provisioning script perform the following:

  • Create your csv file with all the site collection configuration information based on the example csv provided and locate it in c:\temp on your machine running the PowerShell script.
  • Run Windows PowerShell and copy and paste the following command at the command prompt:
Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/colinjwood/CodeCobra/master/CSVProvisioning/createSiteCollectionsFromCSV.ps1')
  • Enter the url of your SharePoint online tenant:

image

  • The site collections will be provisioned in your tenant based on the configurations provided in the csv file. To confirm progress check the Site list in the SharePoint Admin are of your tenant.

This gives you an example of how to configure all or some of the site collections in your Office 365 tenant and create them with one script. This could form the basis of any scripts you write to perform site collection provisioning.

Advertisements

Create a SharePoint site collection in an Office 365 Tenant with PnP PowerShell

Before getting started with PnP PowerShell you need to ensure you have the pre-requisites enabled on your machine. I have detailed the pre-reqs here in previous GitHub repos I have done for our products here at OnePlace Solutions and as we will be targeting SharePoint Online we need to ensure we install the PnP cmdlets for SharePoint online only: https://github.com/OnePlaceSolutions/EmailColumnsPnP

This blog post details how you can create a site collection in an Office 365 tenant using PowerShell.

I have added a PowerShell script to my GitHub repo https://github.com/colinjwood/CodeCobra which I will go through in more detail.

The script that provisions the site collection is here: https://github.com/colinjwood/CodeCobra/blob/master/createSiteCollection.ps1

This script prompts for key information to provision the site collection with. The site template is based on the standard ‘Team Site’ template in SharePoint, however this information could be prompted for and added dynamically to your script.

To execute this script and provision a site collection do the following:

  • Start PowerShell on your machine
  • Copy and paste the following command into your PowerShell command window:
    Invoke-Expression (New-Object Net.WebClient).DownloadString(‘https://raw.githubusercontent.com/colinjwood/CodeCobra/master/createSiteCollection.ps1')
    
  • Enter your SharePoint tenant url and you will be prompted to login, use your email address :

SNAGHTML8f385c2

  • Enter the url of your new site collection to be provisioned:
  • SNAGHTML9009eba

    • Enter the site owner of your new site collection by typing in the email address
    • Enter the timezone, I type 76 as I live in Sydney
    • The new site collection will now be provisioned in Office 365. To confirm and check progress go into the SharePoint Admin area of your tenant and go to the list of site collections and you will see your new site collection:

    SNAGHTML961a9ce

    The command used in this script is:

    New-PnPTenantSite

    Here is the official documentation on this cmdlet: https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/New-PnPTenantSite.md

    I extend the provisioning process in my other blog post where administrators can create a csv file defining multiple site collections, the template they are based on, the urls, site owners, regional settings etc. and provision them all with PowerShell in an Office 365 tenant:

    https://colinjwood.wordpress.com/2017/12/14/provision-multiple-sharepoint-site-collections-with-pnp-powershell/

    Save emails and documents to SharePoint in the background

    Recently, myself and the dev team at OnePlace Solutions completed a challenging yet very rewarding project.

    We are all about user productivity and SharePoint adoption and the results of this project are significant gains in both of these areas.

    Please check out my blog on our company website which details the new background save of emails and documents to SharePoint:

    https://www.oneplacesolutions.com/news/increase-user-productivity-by-saving-documents-and-emails-to-sharepoint-while-working-on-other-tasks.html

    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
    }
    

    Open pdfs in Office 2013 Web Apps

    Great to see that Office web apps 2013 support opening pdfs: http://blogs.office.com/b/officewebapps/archive/2013/07/03/pdfs-in-the-word-web-app.aspx

    Pdfs have always been a special case to deal with in SharePoint, setting their custom icon for display in libraries and indexing them for search etc. It’s good to see Microsoft acknowledging them and now allowing you to open them up in in the Word Web app.

    Here is a good technical article on configuring it on-premise (Office 365 should have it all pre-configured for you):

    http://melcher.it/2013/05/install-office-web-apps-2013-for-sharepoint-2013-with-pdf-preview/

    Harness the power of SharePoint Office 2013 Web Apps in Outlook

    SharePoint 2013 Web Apps are a substantial leap forward from the SharePoint 2010 offering. They offer rich editing capabilities so now you can truly survive without having Office installed on your machine.

    One of the other nice features is the preview of Office documents in SharePoint 2013 when selecting an item in a document library (.docx, .xlsx, .pptx).

    image

    The latest update to Office 2013 web apps now supports pdf files which can be previewed by Word 2013 web apps :

    http://blogs.office.com/b/officewebapps/archive/2013/07/03/pdfs-in-the-word-web-app.aspx.

    You can also benefit from this preview capability in SharePoint 2013 search results allowing you to make quick decisions as to whether it is the correct document or not. This is just one of the many nice search enhancements out-of-the-box in SharePoint 2013:

    image

    With all this investment been made in Office 2013 web apps by Microsoft, it would be nice if we could tap into some of this action from users desktop applications.

    With the latest offering of OnePlaceMail (6.5 http://www.scinaptic.com/news/sharepoint-access-within-a-familiar-microsoft-outlook-style-interface.html) this is exactly what we have done. Users can navigate to or search for content while still in Outlook and quickly execute a real-time preview of that content. A real focus has been on adoption and with that we now provide a rich embedded Outlook style interface for viewing SharePoint content in Outlook. We have tapped into the Office 2013 web app preview for showing document previews embedded in Outlook as if a user were previewing any Outlook item.

    Benefits of web app preview in Outlook:

    • Instant access to content embedded in Outlook – no need to jump out to the browser to open SharePoint documents.
    • Quick, efficient access – no need to download the entire file locally to view content.
    • Can quickly launch document in native office application for full rich editing capabilities.
    • Intuitive to users – familiar Outlook style interface.
    • Perform a SharePoint search and preview results all within Outlook.

    Document preview in Outlook:

    image

    Search result preview in Outlook:

    image

    As we are leveraging the SharePoint 2013 Web Apps preview we will also benefit from any enhancements and any support for new file formats going forward. If you are a SharePoint Online (Office 365) company the web app server is already provisioned for you so there is no additional setup/installation required in order to start benefiting from the 2013 web apps either in SharePoint via the browser or in Outlook with OnePlaceMail installed.

    If you are on-premise and do not have Office 2013 web apps up and running here is a good place to start: http://technet.microsoft.com/en-us/library/jj219455.aspx.

    By providing the preview in Outlook we are bringing SharePoint content to the user where they work throughout the day. Before you know it your users will be accessing the SharePoint platform without them realising it, helping with the adoption problem and  maximizing your investment in SharePoint.