SharePoint Online: Allow Members to Edit Group Membership using PowerShell

Requirement: Configure SharePoint Online Group to manage membership by Group Members.

How to Allow Members of the Group to Manage Group?

Microsoft SharePoint Online Groups offers an easy way to manage users and their membership. As an Administrator, You can add or remove members or delegate permissions so that existing group members can invite other people to the group. This guide will show you how to set up who can manage group memberships in SharePoint Online.

Follow these steps to change a group’s group settings in SharePoint Online.

  1. Go to Site Settings >>  Click on the “People and Groups” link
  2. Pick the group, you want to change the group settings from the left navigation.
  3. From the group page, Click on Settings >> Group Settings in the toolbar.
  4. Under Group Settings, for “Who can edit the membership of the group?, set the “Group Members” option.
    sharepoint online group settings
  5. Click “OK” to save your changes.

With these changes, members of the group will be able to add or remove other members from the group. This can be a useful feature for organizations that want to allow members of a group to manage the membership of the group without requiring administrative access to the site collection.

PowerShell to Update Group Settings to Allow Members to Manage Group:

Let’s explore how to allow members to edit group membership using PowerShell. Here is how to automate the above group settings:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
    
#Config Parameters
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
 
#Setup Credentials to connect
$Cred = Get-Credential
  
Try {
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.UserName,$Cred.Password)
    
    #Get All Groups of the Site
    $SiteGroups = $Ctx.web.SiteGroups
    $Ctx.Load($SiteGroups)
    $Ctx.ExecuteQuery()
 
    #Iterate through each Group - Exclude SharePoint Online System Groups!
    ForEach($Group in $SiteGroups | Where {$_.OwnerTitle -ne "System Account"})
    {
        #Update Group Settings: Who can edit the membership of the group? to Grop Members
        $Group.AllowMembersEditMembership = $True
        $Group.Update()
        $Ctx.ExecuteQuery()
        Write-host -f Green "Group Settings for '$($Group.Title)' Updated to Edit Membership by Group Members!"
    }    
}
Catch {
    write-host -f Red "Error Updating Group Settings!" $_.Exception.Message
}

PnP PowerShell to Change Group Settings:

To change a group setting to allow group members to edit group membership using PnP PowerShell, use:

#Variable
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"
$GroupName ="Marketing Team Site Owners"

#Connect to PnP Online
Connect-PnPOnline $SiteURL -Credentials (Get-Credential)

#Set Group Settings
Set-PnPGroup -Identity $GroupName -AllowMembersEditMembership $True

To update group settings for all groups in a site collection, use the following:

#Variable
$SiteURL= "https://crescent.sharepoint.com/sites/marketing"

#Connect to PnP Online
Connect-PnPOnline $SiteURL -Credentials (Get-Credential)

#Get All Groups of the Site collection
$SiteGroups = Get-PnPGroup -Includes AllowMembersEditMembership

ForEach($Group in $SiteGroups)
{
    If($Group.AllowMembersEditMembership -ne $True)
    {
        Set-PnPGroup -Identity $Group -AllowMembersEditMembership $True
        Write-host -f Green "Group Settings for '$($Group.Title)' Updated to Edit Membership by Group Members"
    }
}

Similarly, to configure group settings for all site collections in the tenant, use the following script:

#Variable
$AdminCenterURL = "https://crescent-admin.sharepoint.com"

#Get Credential to connect 
$Cred = Get-Credential

#Connect to Admin Center
Connect-PnPOnline $SiteURL -Credentials $Cred

#Get All Site Collections - Exclude: Mysite Host, App Catalog, eDiscovery and Bot catalog Sites
$Sites = Get-PnPTenantSite -Detailed | Where { $_.Template -ne "SPSMSITEHOST#0" -and $_.Template -ne "STS#-1" -and $_.Template -ne "APPCATALOG#0" -and $_.Template -ne "EDISC#0"}
Write-host "Total Number of Sites:"$Sites.Count

ForEach($Site in $Sites)
{
    Try {
        #Connect to Site collection
        Write-host -f Yellow "Processing Site Collection:"$Site.URL
        Connect-PnPOnline $Site.URL -Credentials $Cred

        #Get All Groups of the Site collection - Exclude SharePoint Online System Groups!
        $SiteGroups = Get-PnPGroup -Includes AllowMembersEditMembership | Where {$_.OwnerTitle -ne "System Account"}
        ForEach($Group in $SiteGroups)
        {
            If($Group.AllowMembersEditMembership -ne $True)
            {
                Set-PnPGroup -Identity $Group -AllowMembersEditMembership $True
                Write-host -f Green "`tGroup Settings for '$($Group.Title)' Updated to Edit Membership by Group Members"
            }
        }
    }
    Catch {
        write-host -f Red "`tError Getting Site Collection!" $_.Exception.Message
   }
}

In summary, By allowing members to edit group membership using PowerShell, organizations can improve collaboration and teamwork by streamlining the process of adding and removing members from groups. You can also delegate group management responsibilities to members, reducing the workload of administrators and allowing them to focus on more critical tasks.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

Your email address will not be published. Required fields are marked *