Add M365 Group and Enable Team in SPO Site using PnP PowerShell

In this post, we will explore how to connect a new Microsoft 365 group with an existing SharePoint Online site and enable Microsoft Teams by using the PnP PowerShell. We have already explained how to Create Group and Enable Teams in Existing SPO Site using SPO Management and Microsoft Teams PowerShell modules.

In the PnP PowerShell module, we can use the Add-PnPMicrosoft365GroupToSite command to connect an existing classic team site with a new Microsoft 365 group. Then, use the New-PnPTeamsTeam command to create a new Microsoft Teams team from the newly created and site-connected 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 Admin Site
Connect-PnPOnline -Url $AdminSiteURL 

Add Microsoft 365 group to an existing SharePoint Online site

Use this command to add a new Microsoft 365 Unified group to an existing classic team site collection (Groupify). This command allows you to convert a classic team site to a modern team site by creating a new M365 group and connect the site with the newly created group.

#Provide your classic team site URL
$SiteURL = "https://contoso.sharepoint.com/sites/salesteamsite"

#Provide display name and mailNickName for the new group
$GroupName = "Sales Team Group"
$GroupAlias = "SalesTeamGroup"

#Groupify - Connect the classic team site to a new M365 group
Add-PnPMicrosoft365GroupToSite -Url $SiteURL -Alias $GroupAlias -DisplayName $GroupName

Enable Teams in an existing Microsoft 365 group

Once a new M365 group is added to the classic team site, we can use the below command to create a new Microsoft Teams team (Teamify) using the newly created group which is connected with the site.

#Provide your team site URL which is connected with a group
$SiteURL = "https://contoso.sharepoint.com/sites/salesteamsite"

#Get the id (Group Id) of the connected group
$SiteInfo = Get-PnPTenantSite -Identity $SiteURL
$GroupId = $SiteInfo.GroupId.Guid

#Teamify - Enable Teams in the group which is connected with the site
New-PnPTeamsTeam -GroupId $GroupId
Advertisement

Leave a Comment