In this post, we will explore how to create a new team site or communication site in SharePoint Online using PnP PowerShell. We can use the New-PnPSite cmdlet to create a communication site, a modern team site with Microsoft 365 group, or a modern team site not connected to group.
Ensure that you have already installed the latest PnP PowerShell module. Before you start, run the below commands to connect the PnP PowerShell module with your SharePoint Online admin site.
#Provide your SharePoint Online Admin center URL
$AdminSiteURL = "https://contoso-admin.sharepoint.com"
#$AdminSiteURL = "https://<Tenant_Name>-admin.sharepoint.com"
#Connect to SharePoint Tenant Admin Site
Connect-PnPOnline -Url $AdminSiteURL
Summary
- Create a new Team Site with Microsoft 365 group
- Create a new Team Site without Microsoft 365 group
- Create a new Communications Site collection
- Get or Retrieve SPO Site collection details
Create a new Team Site with Microsoft 365 group
Use this command to create a new Modern Team Site collection with M365 group. The command uses the same Alias value for the new Site URL (Site Alias) and mailNickName for the new group (Mail Alias).
New-PnPSite -Type TeamSite -Title "HR Team Site" -Alias "HRTeamSite"
We need to use the SiteAlias parameter to specify different alias for the Site URL. If the SiteAlias parameter is specified, a site collection will be created based on its value, otherwise, the value specified in the Alias parameter will be used.
The below command creates a new team site collection with the URL “https://tenant.sharepoint.com/sites/sales-team-site”. The underlying M365 group will have “sales-team-group” as the alias.
$SiteAlias = "sales-team-site"
$GroupAlias = "sales-team-group"
New-PnPSite -Type TeamSite -Title "Sales Team Site" -SiteAlias $SiteAlias -Alias $GroupAlias
Create a new Team Site without Microsoft 365 group
We need to specify the Type parameter value as “TeamSiteWithoutMicrosoft365Group” to create a new Modern team site collection without the M365 group.
New-PnPSite -Type TeamSiteWithoutMicrosoft365Group -Title "Resource Site" -Url "https://contoso.sharepoint.com/sites/resource-site"
Note: The New-PnPSite cmdlet currently supports creating only ‘Modern’ sites (Communication Site and Team site with or without Microsoft 365 group). If you want to create a classic site, use New-PnPTenantSite.
Create a new Communications Site collection
Use this command to create a new Communication Site collection.
New-PnPSite -Type CommunicationSite -Title "Test-Site-C1" -Url "https://contoso.sharepoint.com/sites/test-site-c1"
Get or Retrieve SPO Site collection details
We can use the Get-PnPTenantSite cmdlet to get all site collections or individual site collection information. The below command returns all site collections with full details information.
Get-PnPTenantSite -Detailed
To fetch a single site collection information, we need to pass the Site URL or Site ID value.
Get-PnPTenantSite -Identity "https://contoso.sharepoint.com/sites/sales-team-site"