Create a Modern Site Collection in SharePoint Online using PowerShell

Requirement: Create a modern site collection in SharePoint Online with PowerShell.

How to create a Modern Team Site in SharePoint Online?

SharePoint Online Modern team sites allow people to work together, collaborate, and share documents and messages. They provide a whole new user experience with their intuitive design, responsive UI optimized for mobile devices, and faster page loading. By default, when you create a site in the SharePoint Online admin center, it creates a modern team with an associated Office 365 group. How to create a modern site collection in SharePoint Online? Well, To create a modern SharePoint Online Site collection, follow these steps:

  1. Login to New SharePoint Admin Center as a tenant admin or SharePoint Online Administrator. 
  2. Click on Sites >> Active Sites from left navigation >> Click on “Create”.
  3. Click on “Team site” to create a modern team site in SharePoint Online.
    create modern site collection sharepoint online powershell
  4. Provide the site Name, URL, and Group owner options, and click on “Finish” to create a modern site collection in SharePoint Online. sharepoint online create modern team site powershell
  5. To set Privacy settings and language, you can expand “Advanced Settings” and select the site’s privacy, whether it’s a private site or a public site accessible to everyone in the organization. Then, click the Next button.
    sharepoint online create private site collection

Wait for a moment, and your site collection should appear in the site collections list. A modern team site with an associated Microsoft 365 group, with services such as Planner, a shared Calendar, etc. created successfully.

BTW, You can create a new site collection from the SharePoint Online start page as well (https://<tenant>.sharepoint.com/_layouts/15/sharepoint.aspx). Now, let’s see how to create a modern team site without a group in SharePoint Online using PowerShell.

SharePoint Online: Create Modern Team Site Collection using PowerShell

The SharePoint Online PowerShell cmdlets are a great way to automate your day-to-day tasks. You can create site collections, move site collections, or provision sites in bulk with ease. It is an incredibly powerful tool that will allow you to do more in less time. Here, in this case, You can create a modern site collection in SharePoint Online by specifying the site template as “STS#3”:

#Connect to SharePoint Online
Connect-SPOService -url "https://crescent-admin.sharepoint.com" -Credential (Get-credential)
  
#Create a modern team site
New-SPOSite -Url "https://crescent.sharepoint.com/sites/Purchase" -Owner "[email protected]" -StorageQuota 2048 -Title "Purchase Team Site" -Template "STS#3"

Create Modern Site Collection in SharePoint Online using PowerShell

SharePoint modern team sites allow you to share information with your team in the organization. You can use a team site to store and collaborate on files and manage lists of information. Let’s create a new team site with modern experience using PowerShell in SharePoint Online:

#PowerShell to create modern 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!")
    )
 
#Connection parameters 
$AdminURL = "https://crescent-admin.sharepoint.com"
$AdminName = "[email protected]"
  
Try{
    #Connect to Office 365
    Connect-SPOService -Url $AdminURL -Credential (Get-Credential)
  
    #Check if the site collection exists already
    $SiteExists = Get-SPOSite | Where {$_.URL -eq $URL}
    
    #Check if the site exists in the recycle bin
    $SiteExistsInRecycleBin = Get-SPODeletedSite | where {$_.url -eq $URL}
 
    If($SiteExists -ne $null)
    {
        write-host "Site $($url) exists already!" -foregroundcolor Yellow
    }
    elseIf($SiteExistsInRecycleBin -ne $null)
    {
        write-host "Site $($url) exists in the recycle bin!" -foregroundcolor Yellow
    }
    else
    {
        #sharepoint online create modern site collection powershell
        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 = "Purchase"
$SiteURL= "https://crescent.sharepoint.com/sites/purchase"
$SiteOwner = "[email protected]"
$StorageQuota = 2048
$SiteTemplate = "STS#3"
 
#Call The function to create site collection in SharePoint Tenant
Create-SPOSite -Title $SiteTitle -URL $SiteURL -Owner $SiteOwner -StorageQuota $StorageQuota -Template $SiteTemplate

If you want to create a classic site in SharePoint Online, use: Create classic site in SharePoint Online

PnP PowerShell to Create Modern Site

If you want to create a new modern team site collection with Office 365 group, use New-PnPSite cmdlet of PnP PowerShell in SharePoint Online. Make sure the PnP PowerShell module is installed before creating a new SharePoint site collection.

New-PnPSite -Type TeamSite -Title "Test Modern TeamSite" -Alias TestModernTeamSite -IsPublic

Let’s wrap it inside a function and add some error handling to the PnP PowerShell script to create a modern site for your SharePoint environment:

#Define Variables
$AdminCenterURL = "https://crescent-Admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/procurement2"
$SiteTitle = "crescent Procurement Portal"
$SiteOwner = "[email protected]"
$Template = "STS#3" #Modern Team Site
$Timezone = 24 #GMT+4
 
Try
{
    #Connect to Tenant Admin
    Connect-PnPOnline -URL $AdminCenterURL -Interactive
     
    #Check if site exists already
    $Site = Get-PnPTenantSite | Where {$_.Url -eq $SiteURL}
 
    If ($Site -eq $null)
    {
        #sharepoint online pnp powershell create site collection
        New-PnPTenantSite -Url $SiteURL -Owner $SiteOwner -Title $SiteTitle -Template $Template -TimeZone $TimeZone -RemoveDeletedSite
        write-host "Site Collection $($SiteURL) Created Successfully!" -foregroundcolor Green
    }
    else
    {
        write-host "Site $($SiteURL) exists already!" -foregroundcolor Yellow
    }
}
Catch {
    write-host "Error: $($_.Exception.Message)" -foregroundcolor Red
} 

How do you create a modern team site without a Microsoft 365 group? SharePoint Online: Create Modern Team Site without Group

Wrapping up

In conclusion, creating modern SharePoint Online sites is a powerful way to improve the user experience, collaboration and productivity. By using the SharePoint Online user interface, or PowerShell, administrators can easily create modern sites that are mobile responsive, easy to use and visually appealing. The process of creating modern SharePoint Online sites is relatively simple, and can be done in a few clicks, or by using a few lines of code.

How do I convert a team site to a Communication site in SharePoint Online?

You can convert a Classic Team site into a Communications site, using the “Enable-SPOCommSite” PowerShell cmdlet. But, You can’t convert Modern Team sites or sites connected to Microsoft 365 group to modern communication site. If you need full-width pages, You can simply disable the quick launch, however.
More info: SharePoint Online: Convert team site to communication site

How do I convert the root site to a communication site?

Other than enabling communication site features with PowerShell, You can create a new communication site and swap it with the Root site (https://YourDomain.SharePoint.com) using the “Invoke-SPOSiteSwap” cmdlet.
More info: Convert Root site to communication site in SharePoint Online

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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