PowerShell to create Team site in SharePoint Online
Image: team site in SharePoint Online

Hello SharePointers,

In today’s article, we will learn about How to create a Team Site in SharePoint Online with PowerShell. This is the second part of the article series about creating SharePoint sites. In the last part, we learned about how to create a communication site in SharePoint Online using PowerShell. If you newly joined this blog and want to learn about the creation of the Communication site in SharePoint Online, then please click on how to Create a Communication site in Share Point Online.

Okay, That’s enough about the background. Let us move on to our current topic about How to create a TEAM site in SharePoint Online using PowerShell.

Requirement:

Create a Modern/Classic Team site in SharePoint Online using PowerShell.

What is the TEAM site in SharePoint?

As per Microsoft, A SharePoint Team site Connects you and your team to the content, information, and apps you rely on every day. For Example, A team site can be used to store and collaborate on files or to create and manage lists of information.

Types of Team site in SharePoint.

In SharePoint Online there are two types on Team site, and they are as below.

  1. Classic Team Site
  2. Modern Team Site

Classic Team Sites:

Classic Team sites are the team sites which are created based on STS#0 Template. This sites are NOT associated with Office 365 Groups. These type of sites have a User Interface same like as SharePoint 2013 sites. Please see image below.

PowerShell to create Team site in SharePoint Online
Img: Classic Team site

Modern Team Site:

Modern Team sites are the Team sites which are associated with Office 365 Groups. The Modern Team sites are created with “GROUP#0” Template of SharePoint Online. The Modern Team sites have a modern pages user interface. Please see image below.

PowerShell to create Team site in SharePoint Online
Image: team site in SharePoint Online

So Now we will see How to create Team Site n SharePoint online.

Create a Team site in SharePoint Online.

Please follow the below steps to create a new communication site in SharePoint Online.

  • Login to New SharePoint Admin center as tenant administrator or SharePoint Online Administrator.
  • Click on “Sites” >> “Active Sites” from the left navigation >> Click on “Create” from available options >> select “Communication site” to create a new communication site.
  • Fill the site properties like “site name” which will automatically become a URL of the site. The team sites are created under the /sites/ managed path by default, but you can change it to /Teams / if required.
  • If you notice in below screen, the feild “Group Email Address” is nothing but a Office 365 group mailbox id, Which is automatically taken as per the site name. This means SharePoint will automatically create an Office 365 group as per the site name.
  • Give the Site Description if required.
  • Set Privacy Settings and Site Language.
  • Team site in SharePoint Online PowerShell
    Create SharePoint Team Site

    Click on Next  and this will create your Modern Team site associated with Office 365 Group.

  • Here We go, Let’s see how our site looks.
    PowerShell to create Team Site
    Final “SharePointGems” Team Site

     

  • Ok, That’s, enough about the Manual Process and Let’s create Team site Using PnP PowerShell.

Create SharePoint Online Team site using PowerShell.

We can create Team site in Two ways, Using SharePoint Online Management Shell, and Patterns & Practices for PowerShell That means PnP PowerShell.

Using SharePoint Online Management Shell (SPO Service) [creates Classic Team Site]
#Declare Parameters
$AdminCenterUrl = "https://spforfun-admin.sharepoint.com"
$SiteUrl = "https://Spforfun.sharepoint.com/sites/ShareP  ointgems"
$SiteTitle = "SharePoint Gems"
$siteOwner = "sarang@spforfun.com"

#Connect SharePoint Online
Connect-SPOService -Url $AdminCenterUrl -credentials (Get-Credential)

#Poershell to create new communication site
New-SPOSite -Url $SiteUrl -Owner $SiteOwner -Template "STS#3"  -Title $SiteTitle -StorageQuota 1048

    The above block of code will a Classic Team site in the SharePoint Online Platform.

Now let us move ahead and create a Team site Using PnP PowerShell.

    Create Modern Team Site Using PnP PowerShell

Below the Single line of code will do our work, which means it will create a Modern Team site associated with Office 365 Group.

  New-PnPSite -Type "Team Site" -Title "SharePoint Gems" -Alias "sharepointgems"

This will create a new Modern Team site with Title “SharePoint Gems” and the URL                             ‘https://tenant.sharePoint.com/sites/sharepointgems’ OR ‘https://tenant.sharePoint.com/teams/sharepointgems’ based on the managed path configuration in the SharePoint Online Admin Portal.

    Full Line of code goes here.
#Declare all variables
$AdminCenterUrl = "https://spforfun-admin.sharepoint.com"
$SiteUrl = "https://Spfordun.sharepoint.com/teams/SharePointgems"
$SiteTitle = "SharePoint Gems"
$siteAlias = "SharePointGems"

#Get Credentials to connecct
$cred = Get-Credentials
Try
{
  #connect Admin site
  Connect-PnPOnline -Url $AdminCenterUrl -Credentials $Cred
  
  #Check if site exist
  $site = Get-PnpSite| Where {$_.Url -eq $SiteUrl}
  
  If ($Site -eq $null)
  {
    #SharePoint Online PnP Powershell to create communication site
    New-PnPSite -Type "Team Site" -Title $SiteTitle -Alias $siteAlias   
   write-Host "Site Collection $SiteUrl created Successfully!" -f Green
  }
  else
  {
    write-Host "Site $SiteUrl already Exist!" -f Yellow
  }
}
Catch
{
 wirte-Host "Error Occurred $($_.Exception.Message)" -f Red
}

You can create multiple team sites by creating a “.csv” file of multiple URL and reading in PnP Powershell.

If we want to create the same then we need to add foreach loop in the above code.

And That’s it. Bingo !!! we have successfully created a Team site using both the methods of PowerShell.

See more tutorials of SharePointgems

know more about new-pnpsite here.

10 thoughts on “PowerShell to create Team Site in SharePoint Online”
  1. I’m the manager of JustCBD Store brand (justcbdstore.com) and I am currently seeking to broaden my wholesale side of company. I am hoping anybody at targetdomain share some guidance ! I thought that the most ideal way to accomplish this would be to reach out to vape shops and cbd stores. I was really hoping if anyone could suggest a qualified website where I can purchase CBD Shops B2B Database I am presently examining creativebeartech.com, theeliquidboutique.co.uk and wowitloveithaveit.com. On the fence which one would be the very best solution and would appreciate any support on this. Or would it be much simpler for me to scrape my own leads? Ideas?

Leave a Reply