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 who can manage group memberships in SharePoint Online.

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

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

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

Let’s automate the above group settings change using PowerShell:

#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:

#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 all site collections in the tenant:

#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
   }
}

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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