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?
Follow these steps to change the group settings of a group in SharePoint Online.
PnP PowerShell to Change Group Settings:
To change a group settings to allow group member to edit group membership using PnP PowerShell, use:
To update group settings for all groups in a site collection, use:
Similarly, to configure group settings all site collections in the tenant:
How to Allow Members of the Group to Manage Group?
Follow these steps to change the group settings of a group in SharePoint Online.
- Go to Site Settings >> Click on "People and Groups" link
- Pick the group you want 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 "Group Members" option.
- Click "OK" to save your changes.
#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 settings to allow group member 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 } }
No comments:
Please Login and comment to get your questions answered!