Recreate deleted owner groups for SharePoint sites connected with M365

Recreate deleted owner groups for SharePoint sites connected with M365

If out-of-the-box (OOB) groups such as owners, members, or visitors, have been accidentally deleted from your SharePoint site, these steps will help you restore them.
End users can unintentionally delete default SharePoint groups, resulting in a groupless state.

Recovery process

Rebuilding SharePoint owner, member, and visitor groups is critical to restoring normal. Use the link {siteUrl}_layouts/15/permsetup.aspx to recreate the missing groups. Further details can be found at:https://learn.microsoft.com/en-us/answers/questions/526452/sharepoint-online-restoring-deleted-permission-gro


The newly created owner group is not associated with the M365 group owners. If a user is added as owner through the modern permission interface, they do not receive permissions for the site by default. Check permissions.

Restore the connection

It is necessary to reconnect the M365 group owners to SharePoint owners. When a team site connected to M365, the M365 group owners are added to the SharePoint owner group.
Further details can be found in the article:
how the M365 group is associated with the SharePoint groups.

We need to run a script.

      1. connect-pnpOnline -Url https://[Yourdomain].sharepoint.com/sites/[Yourpage] -weblogin

      2. $m365GroupId = (get-pnpsite -Includes RelatedGroupId).RelatedGroupId

      3. $m365GroupOwnerClaims = "c:0o.c🙂federateddirectoryclaim provider🙂{0}_o" -f $m365GroupId.Guid.ToString()

      4. Add-PnPSiteCollectionAdmin -Owners $m365GroupOwnerClaims

      5. $owner = Get-PnPGroup -AssociatedOwnerGroup 🙂 select Title

      6. Add-PnPGroupMember -Group $owner.Title -LoginName $m365GroupOwnerClaims 🙂 Out-zero

AfterTo execute the script, the M365 group owners with the SharePoint owner groupconnected.