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/

    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 )

    w

    Connecting to %s