In Microsoft 365, a single SharePoint site can be easily created using SharePoint Admin center. Usually when we are doing content migrations to SharePoint online, we need to map the site collection URLs for source and destinations in migration tools. And for that all SharePoint site collections need to be created prior the migration so we can map them the site URLs in migration tools.

A user with SharePoint admin role can create a SharePoint site collection by going to the SharePoint Admin center or can use PowerShell cmdlet for creating the sites. Below is cmdlet example for creating a simple site collection:

New-SPOSite -Url “url for the site” -Owner “email address of site owner” -StorageQuota 2048 -Title “Site title” -Template “site template id”

Now, it would be the best option to use PowerShell scripts when we need to create multiple site collections. Just prepare a csv file where you can mention details for below fields

  • Site Title
  • Site URL
  • Owner Email

You can also take quota in csv file, but in current example, I am just adding 2 GB of file quota for all site collections.

PowerShell Script to Create Site collections in bulk

Below is the script to create site collections, you can modify the parameters for Tenant URL and CSV File:

$TenantUrl = "https://MSTalk-admin.sharepoint.us"
$CSVPath = "D:\newsitelist.csv"
 
Connect-SPOService -Url $TenantUrl  


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 = "spAdmin@Mstalk.onmicrosoft.us"
        $Template = "STS#3"
        
 
        #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-SPOSite -Url $Url -Owner $Owner -StorageQuota 2048 -Title $Title -Template $Template

         }
        Else
        {
            write-host "Site $($URL) exists already!" -foregroundcolor Yellow
         }
    }
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
}

Adnan, a distinguished professional, boasts an impressive track record as a Microsoft MVP, having achieved this prestigious recognition for the eighth consecutive year since 2015. With an extensive career spanning over 18 years, Adnan has honed his expertise in various domains, notably excelling in SharePoint, Microsoft 365, Microsoft Teams, the .Net Platform, and Microsoft BI. Presently, he holds the esteemed position of Senior Microsoft Consultant at Olive + Goose. Notably, Adnan served as the MCT Regional Lead for the Pakistan Chapter from 2012 to 2017, showcasing his leadership and commitment to fostering growth within the tech community. His journey in the realm of SharePoint spans 14 years, during which he has undertaken diverse projects involving both intranet and internet solutions for both private and government sectors. His impact has transcended geographical boundaries, leaving a mark on projects in the United States and the Gulf region, often collaborating with Fortune 500 companies. Beyond his roles, Adnan is a dedicated educator, sharing his insights and knowledge as a trainer. He also passionately advocates for technology, frequently engaging with the community through speaking engagements in various forums. His multifaceted contributions exemplify his dedication to the tech field and his role in driving its evolution.

Leave a Reply