How to Create a SharePoint Online Site Using PowerShell?

I had to quickly create a SharePoint Team site while working on a project. By writing PowerShell scripts, I fulfilled the necessary requirements.

In this tutorial, I will show you how to create a SharePoint Online site using PowerShell with various examples.

How to Create a SharePoint Online Site Using PowerShell

To create a SharePoint Online Site, we can use SharePoint Online Management PowerShell as well as PnP PowerShell.

Additionally, we can use the Visual Studio Code or Windows PowerShell ISE to execute the PowerShell commands.

NOTE:

-> In SharePoint Online Management Shell, you can create different types of SharePoint sites by changing the Template parameter with the template name. -> In PnP PowerShell, you can change the Type parameter with the type of SharePoint site.

So, let’s start one by one.

Create a SharePoint Online Site from SharePoint Online Management PowerShell

In PowerShell, the New-SPOSite command creates a SharePoint site. This command can be used to create various types of sites, such as a team site, communication site, or any other kind of site.

Specify the necessary parameters, such as site URL, owner, storage quota, and other optional parameters to create a SharePoint Site.

Syntax:

New-SPOSite
   -Owner <String>
   -StorageQuota <Int64>
   -Url <UrlCmdletPipeBind>
   [-Template <String>]
   [-TimeZoneId <Int32>]
   [-Title <String>]
   [-CompatibilityLevel <Int32>]
   [-LocaleId <UInt32>]
   [-NoWait]

Where;

  • Owner: Provide the Microsoft mail account of the SharePoint site owner.
  • StorageQuota: This value specifies the maximum amount of data that can be stored in this site collection in megabytes. It can’t exceed the available store quote for that tenant.
  • Url: Specify the complete URL of the new SharePoint site. It should be in a valid format that follows the tenant’s name. For example, in the case of the talent “szg52”, the valid path is “https://szg52.sharepoint.com/sites/AccountingTeam.”
  • Template: It specifies the type of site template. You can use the “Get-SPOWebTemplate” command to get a list of valid templates. If you don’t specify a template, you can add one later. (For example: STS#3(Team site (no Microsoft 365 group)), STS#0(Team site (classic experience)), SITEPAGEPUBLISHING#0(Communication site))
  • TimeZoneId: It specifies the ID of TimeZone.
  • Title: Specify the title of the SharePoint site.
  • CompatibilityLevel: It is obsolete and can only accept the “15” value.
  • LocaleId: It specifies the SharePoint site collection ID. The Template and LocalId parameters must be valid as returned from the “Get-SPOWebTemplate” command.
  • NoWait: This parameter indicates that the script is executing without any delay.

Create a SharePoint Blank Site using SharePoint Online Management Shell

The Template parameter indicates the site type when creating a SharePoint site. Let’s see what happens if we don’t pass the Template parameter. To do this, follow the example script below.

New-SPOSite -Url "https://szg52.sharepoint.com/sites/HumanResourceManagementTeam" -Owner "PattiF@szg52.onmicrosoft.com" -StorageQuota 2048

In the above script, I just passed all the mandatory arguments.

1. Execute the above script by clicking the RUN button.

create sharepoint site using powershell

2. Open the provided SharePoint site URL. On this page, select the SharePoint site template and click the OK button.

create a sharepoint site using powershell

3. Provide the SharePoint site group permissions and click the OK button.

how to create sharepoint site using powershell

4. The SharePoint site will be created with the Template Name, as shown in the screenshot below. If you provide the Title parameter in the PowerShell script, it will be created with the given title name.

how to create a sharepoint site using powershell

Create a SharePoint Communication Site using SharePoint Online Management Shell

If you want to create the communication site by providing a URL, owner, title, storage quote, template, and local ID, you can follow this PowerShell script as an example.

New-SPOSite -Url "https://szg52.sharepoint.com/sites/ProjectCommunication" -Owner "PattiF@szg52.onmicrosoft.com" -StorageQuota 2048  -Title "Project Communication" -Template "SITEPAGEPUBLISHING#0" -LocaleId 1033

The SharePoint communication site Template is “SITEPAGEPUBLISHING#0,” and the corresponding LocaleId is “1033.”

1. Click the RUN button to execute the above PowerShell Script.

create a sharepoint site using sharepoint online management shell

2. The SharePoint site will be created with the given title. You can access it through the SharePoint admin center or the provided site URL. The site can be viewed as shown in the below screenshot.

how to create a sharepoint site using sharepoint online management shell

Create a SharePoint Online Team Site – Not Microsoft 365 Group connected [Using SharePoint Online Management Shell]

The following PowerShell script created a SharePoint team site with a customized time zone and other proper. The script sets the TimeZone ID to 11, which represents “(GMT-06:00) Central Time (US and Canada),” and sets the CompatibilityLevel to 15. This script is executed immediately without any delay.

New-SPOSite -Url "https://szg52.sharepoint.com/sites/EventPlanning" -Owner "PattiF@szg52.onmicrosoft.com" -StorageQuota 2048  -Title "Event Planning" -Template "STS#3" -NoWait -TimeZoneId 11 -CompatibilityLevel 15

To execute the above command, click on the RUN button.

how to create sharepoint team site using sharepoint online management shell

This PowerShell command will be executed immediately. It will create the SharePoint team site with the provided title. This site is not connected with Microsoft 365 Groups.

Create a SharePoint Online Site from PnP PowerShell

In PowerShell, the New-PnPSite command creates a SharePoint site. Using this command, we can create a communication site or a modern team site connected to the Microsoft 365 groups, not to the Microsoft 365 groups.

The mandatory parameters in this New-PnPSite command are Type, Title, Alia(Team site connected to the Microsoft 365 groups), or URL(Communication site, Team site without connected to the Microsoft 365 groups).

The Syntax for Team site connected with the Microsoft 365 groups:

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>]

The Syntax 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>]

The Syntax for Team site without connected to the Microsoft 365 groups:

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>]
  • Type: This argument specifies the type of site. For example, TeamSite, CommunicationSite, and TeamSiteWithoutMicrosoft365Group.
  • Alias: It represents the shorthand way to provide the site name in the site URL part.
  • Wait: It will wait until the SharePoint site is fully created. This process may take some time.
  • Description: Provide the SharePoint site description.
  • IsPublic: It specifies whether the corresponding SharePoint site is Private or Public. IsPublic means the site is in public mode.
  • SiteDesign: It specifies the custom site design for the SharePoint site, such as Blank, Topic, and Showcase.
  • ShareByEmailEnabled: It specifies to share content through the mail. Owners can invite users who are not part of the organization.
  • Classification: This is used for the new site.
  • TimeZone: Provide the Time Zone in an “Enum TimeZone format.”
  • Connection: Use this parameter to specify an optional connection for the command.
  • HubSiteId: If provided, the site will be linked to the hub site associated with this ID.
  • SiteDesignId: It specifies the users to create and apply a custom design to their SharePoint site.
  • Owners: This parameter specifies one or more users with full access to the SharePoint site and owner permissions. It is only used when creating the SharePoint team site using PnP PowerShell.
  • SensitivityLabel: This sensitivity label should be assigned to the new site.

Create a SharePoint Online Team Site – Microsoft 365 Group Connected [Using PnP PowerShell]

This PowerShell command creates the modern team site connected to the Microsoft 365 groups by adding the admins.

New-PnPSite -Type TeamSite -Title "Event Planning" -Alias EventPlanning -Wait -Description "This site contain all the planning information about sepcific event" -IsPublic -Owners [PattiF@szg52.onmicrosoft.com, JohannaL@szg52.onmicrosoft.com]

1. Click the RUN button to execute the above PowerShell command, as shown in the figure below.

create a sharepoint team site using pnp powershell

2. The created SharePoint site URL is displayed in the terminal. You can access the site through this URL or the SharePoint admin center.

create a modern sharepoint team site using powershell

Create a SharePoint Communication Site using PnP PowerShell

To create a SharePoint communication site and set the Time Zone, Owner, classification, and site design, follow the example command below.

New-PnPSite -Type CommunicationSite -Title "Event Management" -Url "https://szg52.sharepoint.com/sites/EventManagement" -Owner "PattiF@szg52.onmicrosoft.com" -SiteDesign "Blank"  -ShareByEmailEnabled -Classification "HBI" -TimeZone "UTC_MONROVIA"

1. Execute the above PowerShell command by clicking the RUN button.

create sharepoint communication site using pnp powershell

2. After creating the SharePoint site, It will provide the URL in the terminal. You can access the site through this URL. You can observe all the customizations in the screenshot below.

how to create a sharepoint communication site using pnp powershell

Create a SharePoint Online Team Site – Not Microsoft 365 Group Connected [Using PnP PowerShell]

This example command will create the SharePoint team site, which is not connected to the Microsoft 365 groups with the classification HIB.

New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title ProjectPlanning -Classification "HBI" -ShareByEmailEnabled -Url https://szg52.sharepoint.com/sites/ProjectPlanning

1. To execute the above PowerShell command, click the RUN button, as shown in the figure below.

how to create a sharepoint team site using powershell

2. The created SharePoint site URL is displayed in the terminal. You can access the site through that URL.

how to create a sharepoint team site using pnp powershell

This is how we can create the SharePoint site using PowerShell.

In this tutorial, I showed you how to create a SharePoint Site using the SharePoint Online management shell and PnP PowerShell, along with different examples.

I hope these examples will be helpful when you create the SharePoint site using PowerShell.

Moreover, you may also like some more articles: