How to Create a Site in SharePoint Online using PnP PowerShell?

If you have permission, you can manually create a SharePoint site using a browser from the SharePoint admin center. But what about a production environment where these manual activities are restricted? You can use PowerShell. I will show you how to create a SharePoint site using PnP PowerShell.

I will show you examples of:

  • How to create a SharePoint Online group connected team site using PnP PowerShell?
  • How to create a team site without a Microsoft 365 group?
  • How to create a communication site in SharePoint Online using PnP PowerShell?

Create a SharePoint Online Site using PnP PowerShell

If you are new to PnP PowerShell and want to know how to install and work with PnP PowerShell with SharePoint, check out my previous tutorial on PnP PowerShell with SharePoint Online.

Here, we will use the New-PnPSite cmdlet to create a site in SharePoint Online

The New-PnPSite cmdlet in PnP PowerShell is used to create new SharePoint Online sites, including group-connected team sites, team sites without an Office 365 or Microsoft 365 group, and communication sites. This cmdlet allows SharePoint site owners or administrators to specify various parameters, such as site type, title, URL, description, language settings, etc. while creating the site.

Syntax of New-PnPSite (For Team Site):

New-PnPSite -Type TeamSite -Title <String> -Alias <String> [-Description <String>] [-Classification <String>] [-IsPublic] [-Lcid <UInt>] [-Owners <String[]>] [-PreferredDataLocation <Office365Geography>] [-SensitivityLabel <String>] [-HubSiteId <Guid>] [-SiteAlias <String>] [-TimeZone <PnP.Framework.Enums.TimeZone>] [-Wait] [-Connection <PnPConnection>]

Syntax of New-PnPSite (For Communication Site):

New-PnPSite -Type CommunicationSite -Title <String> -Url <String> [-HubSiteId <Guid>] [-Classification <String>] [-SiteDesign <SiteDesign>] [-SiteDesignId <Guid>] [-Lcid <UInt>] [-Owner <String>] [-PreferredDataLocation <Office365Geography>] [-SensitivityLabel <String>] [-TimeZone <PnP.Framework.Enums.TimeZone>]

Syntax of New-PnPSite (For Team Site Without a Microsoft 365 Group):

New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title <String> -Url <String> [-HubSiteId <Guid>] [-Classification <String>] [-SiteDesignId <Guid>] [-Lcid <UInt>] [-Owner <String>] [-PreferredDataLocation <Office365Geography>] [-SensitivityLabel <String>] [-TimeZone <PnP.Framework.Enums.TimeZone>]

1. Create a Group Connected Team Site in SharePoint Online

A group-connected team site in SharePoint Online is integrated with Microsoft 365 Groups. It provides access to a group mailbox, calendar, Planner, OneNote notebook, etc.

You can run the below PowerShell script to create a group-connected team site.

Connect-PnPOnline -Url "https://szg52-admin.sharepoint.com" -Interactive
New-PnPSite -Type TeamSite -Title "Finance Team Site" -Alias "FinanceTeam" -Description "Site for HR Department"

Here:

  • -Type TeamSite specifies the type of site.
  • -Alias is the unique identifier for the Microsoft 365 Group.

Once you execute the above PowerShell script and check the SharePoint admin center, you can see that the site was created. See the screenshot below:

Create a SharePoint site using pnp PowerShell

If you want to create a SharePoint modern team site that everyone in the organization can access, you can pass the -IsPublic parameter. -IsPublic makes the site accessible to everyone in the organization.

Here is the full script:

Connect-PnPOnline -Url "https://szg52-admin.sharepoint.com" -Interactive
New-PnPSite -Type TeamSite -Title "Finance Team Site" -Alias "FinanceTeam" -Description "Site for HR Department" -IsPublic

Read Create a SharePoint Online list using PnP PowerShell

2. Create a Team Site without a Microsoft 365 Group in SharePoint using PnP PowerShell

Now, let me show you how to create a SharePoint Online team site with a group using PnP PowerShell.

I will show you two ways to do it here.

Example-1:

You can use the New-PnPSite cmdlet with the -Type TeamSite parameter and the -Group flag set to $false like below:

Connect-PnPOnline -Url "https://szg52-admin.sharepoint.com" -Interactive

New-PnPSite -Type TeamSite -Title "Finance Team Without Group" -Url "https://szg52.sharepoint.com/sites/FinanceTeamWithoutGroup" -Description "Site for Finance Department" -Lcid 1033 -Template STS#3 -Group $false

Example-2:

You can use the New-PnPSite cmdlet with the -Type TeamSiteWithoutMicrosoft365Group parameter.

Here is the complete script.

Connect-PnPOnline -Url "https://szg52-admin.sharepoint.com" -Interactive

New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title "Finance Team Without Group" -Url "https://szg52.sharepoint.com/sites/FinanceWithoutGroup"

I executed the above PnP PowerShell script, and it created the SharePoint team site without a Microsoft 365 group connected to it.

It also added the user running the PowerShell script as the primary site collection admin. You can see the screenshot below:

create sharepoint team site without group using pnp powershell

3. Create a SharePoint Communication Site using PnP PowerShell

Now, let me show you how to create a communication site in SharePoint Online using PnP PowerShell.

In an organization, we can use communication sites to broadcast messages to all the members. So, by default, everyone in the organization will have access to the SharePoint communication site.

Here, you can use the New-PnPSite cmdlet with the -Type CommunicationSite parameter. Below is the complete script.

Connect-PnPOnline -Url "https://szg52-admin.sharepoint.com" -Interactive

New-PnPSite -Type CommunicationSite -Title "Company News" -Url "https://szg52.sharepoint.com/sites/CompanyNews" -Description "Site for company-wide news and updates" -Lcid 1033

Once you execute the above script, the URL will show after successfully creating the communication site.

create a communication site in sharepoint online pnp powershell

After that, you can also verify in the SharePoint admin center. Look at the screenshot below:

pnp powershell create communication site in sharepoint

I hope now you know how to create a team site in SharePoint Online using PnP PowerShell. I also explained how to create a communication site in SharePoint Online using PnP PowerShell. I explained about both group-connected team sites and team sites without a Microsoft 365 group.

Leave me a comment below if you still have any questions.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.