0

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

1

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

#Parameters $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") #Connection $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 $context.Load($Web) $context.Load($AllProperties) $context.ExecuteQuery() #Change the values for MembersCanShare & AssociatedMemberGroup.AllowMembersEditMembership accordingly $Web.MembersCanShare = $true $web.Update(); $web.Context.ExecuteQuery() $AssociatedMember = $web.AssociatedMemberGroup $context.Load($AssociatedMember) $context.ExecuteQuery() $web.AssociatedMemberGroup.AllowMembersEditMembership = $false $web.AssociatedMemberGroup.Update(); $web.Context.ExecuteQuery() 

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.

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.