I am trying to programmatically set the "Site sharing settings" options under "Site Permissions" -> "Change how members can share" screen on a Modern site. I would like to set the site to the middle option. Basically I want Members to be able to share individual folders but not the entire site.

(This is not the same as making a site public/private, and also not the same as the external sharing settings.)

enter image description here

I would prefer a solution with Microsoft Graph or CSOM but would really be open to any kind of programmatic way to set this (e.g. site designs/site scripts, SharePoint REST API).

The closest thing I have found is the web.MemberCanShare bool property in CSOM but that seems to only toggle between the 1st and 3rd options.

Does anyone know how to set this?

1 Answer 1


Here is a sample script to change site-level sharing settings:

$SiteUrl = "<SiteURL>"  
$UserName = "<Account>"  
$Password = "<Passsword>"

#Load Assemblies
$loadInfo1 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client") 
$loadInfo2 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.Runtime")
$loadInfo3 = [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Client.UserProfiles")

$Securepass = ConvertTo-SecureString $Password -AsPlainText -Force
$context = New-Object Microsoft.SharePoint.Client.ClientContext($SiteUrl)
$context.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($UserName,$Securepass)

$Web = $context.Web
$AllProperties = $Web.AllProperties

#Change the values for MembersCanShare & AssociatedMemberGroup.AllowMembersEditMembership accordingly
$Web.MembersCanShare = $true
$AssociatedMember = $web.AssociatedMemberGroup
$web.AssociatedMemberGroup.AllowMembersEditMembership = $false

Note: This is the second option with

$Web.MembersCanShare = $true
$web.AssociatedMemberGroup.AllowMembersEditMembership = $false

Also, the script does not change the Allow requests settings.

Reference: Changing the "Allow members to share" SharePoint site Access Requests setting using Office Dev PnP.

  • Thank you, this is exactly what I was looking for!
    – Hank
    Mar 17, 2021 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.