In this post, I will explain how to programmatically connect an existing top-level SharePoint Online site to a new Microsoft 365 Group using PowerShell, using the Set-SPOSiteOffice365Group PowerShell command. Before proceeding, install the SharePoint Online PowerShell module and run the following commands:
# Connect to SharePoint ServiceConnect-SPOService -Url "https://<yourtenant>-admin.sharepoint.com"
This example creates a new Microsoft 365 Group named “Group1” and connects the site collection to it. The group will have its privacy set to “Private”
$siteUrl = "https://<yourtenant>.sharepoint.com/sites/site1"$groupName = "group1"$mailNickname = "group1"Set-SPOSiteOffice365Group -Site $siteUrl -DisplayName $groupName -Alias $mailNickname
Thank you for reading
/Simon