Create new site in SharePoint Online with PowerShell

This is part 2 of 10 where we will be creating a new site in SharePoint Online with PowerShell. This is part of the following series:

We will be collecting all available web templates in part 1 so we can use this to create a new site in part 2. In part 3 we will be creating a web for the newly created site. We then want to create a couple of site columns in part 4 which we will combine to a content type in part 5. This content type will be added (part 8) to our newly created document library in part 7 using a list template from part 6. After everything is set we will be setting the view in part 9 for this list to show the added columns we got from adding the content type. We only want to set permissions for myself so I’ll will be breaking the inheritance and setting permissions in part 10.

Create new site in SharePoint Online with PowerShell

This script will create a new site in SharePoint Online based on the specified variables. This script will be not be using CSOM as we have an SPO command to create a new site. We will first start by opening the SharePoint Online Management Shell as administrator which can be downloaded at


You will need to change the first variables to match your Office 365 tenant and copy this bit to PowerShell. You can find all available parameters for New-SPOSite at and the template name using part 1

function new-SPOnlineSite {
# variables that needs to be set before starting the script
$url = ""
$title = "Blog Demo"
$owner = ""
$storageQuota = 1000
$resourceQuota = 50
$template = "STS#0"
$adminUrl = ""
$userName = ""

# Let the user fill in their password in the PowerShell window
$password = Read-Host "Please enter the password for $($userName)" -AsSecureString

# Set credentials
$credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $userName, $password

# Connect to to Office 365
Connect-SPOService -Url $adminUrl -Credential $credentials
write-host "Info: Connected succesfully to Office 365" -foregroundcolor green
write-host "Error: Could not connect to Office 365" -foregroundcolor red
Break new-SPOnlineSite

#verify if site already exists in SharePoint Online
$siteExists = get-SPOSite | where{$_.url -eq $url}

#verify if site already exists in the recycle bin
$siteExistsInRecycleBin = get-SPODeletedSite | where{$_.url -eq $url}

#create site if it doesn't exists
if (($siteExists -eq $null) -and ($siteExistsInRecycleBin -eq $null)) {
write-host "info: Creating $($title)" -foregroundcolor green
New-SPOSite -Url $url -title $title -Owner $owner -StorageQuota $storageQuota -NoWait -ResourceQuota $resourceQuota -Template $template
elseif ($siteExists -eq $true){
write-host "info: $($url) already exists" -foregroundcolor red
write-host "info: $($url) still exists in the recyclebin" -foregroundcolor red


You will be asked to enter the password and press enter


The site will now be created in SharePoint Online so navigate to the SharePoint Admin Center to verify that the site has been created


Leave a Reply

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