SharePoint Online: Bulk Create Multiple Sites with a CSV and PowerShell

Requirement: Create new site collections in SharePoint Online in Bulk from a CSV File using PowerShell.

How to create site collections from a CSV file in SharePoint Online using PowerShell?

Are you a SharePoint Online administrator who needs to create multiple site collections in bulk? Creating multiple site collections in SharePoint Online can be a time-consuming and repetitive task, especially if you need to create many site collections with similar settings. Fortunately, SharePoint Online provides a way to create site collections in bulk using a CSV file and PowerShell scripting.

This blog post will look at creating multiple SharePoint Online site collections. This can be useful if you need to rapidly provision new environments and quickly create a large number of site collections for testing or development purposes. Either way, let’s see how to use PowerShell to create multiple SharePoint Online site collections from a CSV file.

Step 1: Create a CSV file in the below format. Populate the column values according to your requirements. For each site collection, set the below properties:

  1. Site collection Title
  2. Site collection URL
  3. Site Collection Owner
  4. Storage quota, in MB
  5. Resource quota (default is 300)
  6. Site collection template (E.g., Team site template ID STS#0)
powershell to create site collections from csv in sharepoint online

Step 2: Use this PowerShell script to read from CSV, create site collections, and run with SharePoint Online Management Shell.

#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 = ""

#Get Credentials to connect
$Cred= Get-Credential -Message "Enter the Admin Credentials"
$Credentials = New-Object -TypeName System.Management.Automation.PSCredential -argumentlist $Cred.Username, $Cred.Password
    #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

#Read from CSV and create site collection
Import-Csv "C:\Temp\SitesToCreate.csv" | Foreach-Object {
   Create-SPOSite -Title $_.SiteTitle -URL $_.SiteURL -Owner $_.SiteOwner -StorageQuota $_.StorageQuota -ResourceQuota $_.ResourceQuota -Template $_.SiteTemplate  }

This script will loop through each row in the CSV file and create a new site collection using the details in the corresponding columns. Creating SharePoint Online site collections using PowerShell is in my other article: How do I create a SharePoint Online site collection using PowerShell?

PnP PowerShell: Create Multiple Sites from a CSV File

We can also use PnP PowerShell to bulk provision SharePoint Online site collections. Here is my CSV file format. Make sure you replace the “C:\Temp\SitesToCreate.csv” with the correct path to your CSV file.

sharepoint online create multiple site collections from a CSV file using PowerShell

You can download the CSV file from:

PnP PowerShell Script to Create Site Collections in Bulk:

This script will create multiple SharePoint Online Site Collections from the CSV file provided using New-PnPTenantSite cmdlet.

#Set Config Parameters
$TenantUrl = ""
$CSVPath = "C:\Temp\SiteCollections.csv"

#Connect to Tenant
Connect-PnPOnline -url $TenantUrl -Interactive

Try {
    #Get Site Collections to create from a CSV file
    $SiteCollections = Import-Csv -Path $CSVPath

    #Loop through csv and create site collections from each row
    ForEach ($Site in $SiteCollections)
        #Get Parameters from CSV
        $Url = $Site.Url
        $Title = $Site.Title
        $Owner = $Site.Owner
        $Template = $Site.Template
        $TimeZone = $Site.TimeZone

        #Check if site exists already
        $SiteExists = Get-PnPTenantSite | Where {$_.Url -eq $URL} 
        If ($SiteExists -eq $null)
            #Create site collection
            Write-host "Creating Site Collection:"$Site.URL -f Yellow
            New-PnPTenantSite -Url $URL -Title $Title -Owner $Owner -Template $Template -TimeZone $TimeZone -RemoveDeletedSite -ErrorAction Stop        
            Write-host "`t Done!" -f Green
            write-host "Site $($URL) exists already!" -foregroundcolor Yellow
Catch {
    write-host -f Red "`tError:" $_.Exception.Message

After the script finishes executing, You can verify the site collections by going to the SharePoint Online admin center and verifying that the site collections have been created successfully.

In summary, creating multiple site collections in SharePoint Online with a CSV file and PowerShell efficiently saves time and reduces errors. With these simple steps, you can automate the process of creating site collections and enjoy the benefits of a streamlined SharePoint Online environment. Here is another article for a similar requirement in SharePoint On-Premises: How to Create SharePoint Site Collections in Bulk from a CSV File using PowerShell?

Is there a limit to the number of SharePoint Online sites? How many SharePoint sites can I create?

Yes! 2 Million per tenant.

Can we create a subsite in SharePoint online?

Yes! You can still create subsites in SharePoint Online, although Hub sites are the recommended replacements for subsites.
More info: How to Create a subsite in SharePoint Online?

How do I Get all site collections in SharePoint Online?

Use SharePoint Admin Center or PowerShell script to get all sites in the SharePoint Online environment.
More info: SharePoint Online PowerShell to get all site collections

How to create a communication site in SharePoint Online?

To create a communication site, Login to SharePoint Admin Center >> Click on “Sites”>> “Active Sites”>> Click on “Create”>> Choose “Communication Site”, Enter the site name, validate the site address and Click on Finish. You can also create communication sites using PowerShell.
More info: Create a communication site in SharePoint Online with PowerShell

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

Leave a Reply

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