Create Modern Site Collection in SharePoint Online using PowerShell

Requirement: Create modern site collection SharePoint online PowerShell

SharePoint Online: Create Modern Team site using PowerShell
SharePoint Online modern sites provides a whole new user experience by its intuitive design, responsive UI optimized for mobile devices and faster page loading. By default, when you create a site in SharePoint Online admin center, it creates modern team with an associated Office 365 group. To create a modern SharePoint Online Site collection, follow these steps:
  • Login to New SharePoint Admin Center as a tenant admin or SharePoint Online Administrator. 
  • Click on Sites >> Active Sites from left navigation >> Click on "Create"
  • Click on "Team site" to create a modern team site in SharePoint Online.
    create modern site collection sharepoint online powershell
  • Provide the site Name, URL, Group owner options and click on "Finish" to create a modern site collection in SharePoint Online.
    sharepoint online create modern team site powershell
Wait for a moment and your site collection should appear in the site collections list. 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:
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 "Salaudeen@Crescent.com" -StorageQuota 2048 -Title "Purchase Team Site" -Template "STS#3"

Create Modern Site Collection in SharePoint Online using PowerShell
Create modern team site 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 = "SpAdmin@crescent.com"
  
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 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 = "spsadmin@crescent.com"
$StorageQuota = 2048
$SiteTemplate = "STS#3"
 
#Call The function to create site collection
Create-SPOSite -Title $SiteTitle -URL $SiteURL -Owner $SiteOwner -StorageQuota $StorageQuota -Template $SiteTemplate

PnP PowerShell to Create Modern Site
Here is how to create a modern site collection using PnP PowerShell in SharePoint Online
New-PnPSite -Type TeamSite -Title Test Modern TeamSite -Alias TestModernTeamSite -IsPublic
Let's wrap it inside a function and add some error handling to it:
#Define Variables
$AdminCenterURL = "https://crescent-Admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/procurement2"
$SiteTitle = "crescent Procurement Portal"
$SiteOwner = "Salaudeen@crescent.com"
$Template = "STS#3" #Modern Team Site
$Timezone = 24 #GMT+4
 
#Get Credentials to connect
$Cred = Get-Credential
 
Try
{
    #Connect to Tenant Admin
    Connect-PnPOnline -URL $AdminCenterURL -Credential $Cred
     
    #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 to create a modern site without group? SharePoint Online: Create Modern Team Site without Group
Create Modern Site Collection in SharePoint Online using PowerShell Create Modern Site Collection in SharePoint Online using PowerShell Reviewed by Salaudeen Rajack on July 27, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.