kwizcom banner advertisement

SharePoint Online: How to Create New Site Collection using PowerShell?

Requirement: Create a site collection in SharePoint online using PowerShell!

How to Create a Site Collection in SharePoint Online?
Site collection in SharePoint is a logical group sites with a common top-level site and/or zero or more subsites organized as a hierarchy. Every site collection share common top site, navigation, security, content types, etc. To create a SharePoint Online Site collection from Browser, follow these steps:
  • Login to SharePoint Admin Center as a tenant admin or SharePoint Online Administrator. 
  • Click on "Site Collections" from left navigation >> Click on "New" >> and then "Private Site collection" to create a new site collection.
  • The New Site Collection page appears. Set properties according to your requirement to create site collection. Such as: 
    • Title and description for your new site, 
    • Site Address (URL path) for the site
    • Select the Template for your site collection, typically "Team Site" will do. 
    • Set the storage quota, Site collection Primary owner for the site collection. 
    • Click OK to start creating new site collection. Wait for a moment and your site collection should appear in the site collections list.
sharepoint online create site collection

SharePoint Online: PowerShell to create site collection
To create site collections in SharePoint Online using PowerShell, Use: New-SPOSite cmdlet. Here is an example:
#Connect to SharePoint Online
$Credential = Get-credential 
Connect-SPOService -url -Credential $Credential

#Create new Site Collection
New-SPOSite -Url -Owner -StorageQuota 1000 -Title "Marketing Team Site" -Template STS#0 
Wait for a minute and this creates a new site collection in SharePoint online.
sharepoint online powershell create site collection
Now, lets add some error handling, and wrap it inside a re-usable function:

SharePoint online PowerShell to create site:
Lets add some error handling and make the script bit more flexible.. 
#Function to Create Site Collection
Function Create-SPOSite 
        [string]$Title  = $(throw "Please Provide the Site Title!"),
        [string]$URL = $(throw "Please Provide the Site URL!"),
        [string]$Owner = $(throw "Please Provide the Site Owner!"),
        [int]$StorageQuota = $(throw "Please Provide the Site Storage Quota!"),
        [int]$ResourceQuota = $(throw "Please Provide the Site Resource Quota!"),
        [string]$Template = $(throw "Please Provide the Site Template!")

#Connection parameters 
$AdminURL = ""
$AdminName = ""
$AdminPassword="Password Goes here"
$SecurePassword = $AdminPassword | ConvertTo-SecureString -AsPlainText -Force 
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $AdminName, $SecurePassword
    #Connect to Office 365
    Connect-SPOService -Url $AdminURL -Credential $Credentials
    #Check if the site collection exists already
    $SiteExists = Get-SPOSite | where {$_.url -eq $URL}
    #Check if site exists in the recycle bin
    $SiteExistsInRecycleBin = Get-SPODeletedSite | where {$_.url -eq $URL}

    If($SiteExists -ne $null)
        write-host "Site $($url) exists already!" -foregroundcolor red
    elseIf($SiteExistsInRecycleBin -ne $null)
        write-host "Site $($url) exists in the recycle bin!" -foregroundcolor red
        #create the site collection
        New-SPOSite -Url $URL -title $Title -Owner $Owner -StorageQuota $StorageQuota -NoWait -ResourceQuota $ResourceQuota -Template $Template
        write-host "Site Collection $($url) Created Successfully!" -foregroundcolor Green
catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red

#Parameters to create new site collection
$SiteTitle = "Demo"
$SiteURL= ""
$SiteOwner = ""
$StorageQuota = 1000
$ResourceQuota = 300
$SiteTemplate = "STS#0"

#Call The function to create site collection
Create-SPOSite -Title $SiteTitle -URL $SiteURL -Owner $SiteOwner -StorageQuota $StorageQuota -ResourceQuota $ResourceQuota -Template $SiteTemplate 
Now the new site collection will be created in a minute! You can verify by going to SharePoint Online Admin Center.

To create multiple SharePoint Online site collections in bulk from a CSV file, refer: SharePoint Online: Create Multiple Site Collections in Bulk from a CSV File using PowerShell
SharePoint Online: How to Create New Site Collection using PowerShell? SharePoint Online: How to Create New Site Collection using PowerShell? Reviewed by Salaudeen Rajack on June 04, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.