
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
}
No Comments