Creating SharePoint Online Site Collection using PowerShell

Recently, I have been very busy building a new product and been playing a lot with the new (and old) Office 365 APIs and everything around it. The product is cloud based and in a multi-tenant distribution model. I will be blogging more often about the experience and challenges I faced.

Being a multi-tenant product that will be deployed many times, Automating it was the first thing to cross my mind.

I am using PowerShell scripts to create a site collection which will act as the data source for my app.

# 1- get the credentials 
# 2- Connect to the adminstration service
# 3- Create the site collection using the New-SPOSite commandlet

$adminAccount = 'admin@tenant.onmicrosoft.com'

$credentials = Get-Credential -UserName $adminAccount -Message "Enter SharePointOnline credentials"

Connect-SPOService  -Url 'https://tenant-admin.sharepoint.com' 
                    -Credential $credentials

echo 'Connected to Admin Service....'

New-SPOSite -Url 'https://tenant.sharepoint.com/sites/collaboration' 
            -Title 'Collaboration' 
            -Template 'STS#0' 
            -Owner admin@tenant.onmicrosoft.com 
            -NoWait 
            -StorageQuota 1000 
            -ResourceQuota 100 

echo 'Created SiteCollection'

The code is very straight forward three steps:

  1. Get the credentials
  2. Connect to the admin service
  3. Create the new site

Leave a Reply

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