kwizcom banner advertisement

SharePoint Online: Create Multile Site Collections in Bulk from a CSV File using 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?
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 and create site collections and run with SharePoint Online Management Shell.
#Function to Create Site Collection
Function Create-SPOSite 
{
  param
    (
        [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 = "https://crescent-admin.sharepoint.com"
#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
 
Try{
    #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
    }
    else
    {
        #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:\SitesToCreate.csv" | Foreach-Object {
   Create-SPOSite -Title $_.SiteTitle -URL $_.SiteURL -Owner $_.SiteOwner -StorageQuota $_.StorageQuota -ResourceQuota $_.ResourceQuota -Template $_.SiteTemplate  }

This script will create multiple SharePoint Online Site Collections from the .Csv file provided. Here is my another article for similar requirement in SharePoint On-Premises: How to Create SharePoint Site Collections in bulk from a CSV File using PowerShell
SharePoint Online: Create Multile Site Collections in Bulk from a CSV File using PowerShell SharePoint Online: Create Multile Site Collections in Bulk from a CSV File using PowerShell Reviewed by Salaudeen Rajack on September 11, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.