Forum Discussion
Oct 05, 2016
Changing the "Allow members to share" SharePoint site Access Requests setting using Office Dev PnP
How can I set the "Allow members to share the site and individual files and folders" setting using the Office Dev PnP Provisioning Engine or PowerShell commands? I haven't found this specific setting...
SanthoshB1
Oct 06, 2016Bronze Contributor
You can use this script. You need to install CSOM module Version 16.1.4727.1200 and above to use this.
$SiteUrl = "https://<TenantName>.sharepoint.com/sites/<Sitename>"
$UserName = "admin@<TenantName>..onmicrosoft.com"
$Password ="password"
$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")
#$sstr = ConvertTo-SecureString -string $AdminPass -AsPlainText -Force
$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()
$Web.MembersCanShare=$false
$web.Update();
$web.Context.ExecuteQuery()
$AssociatedMember=$web.AssociatedMemberGroup
$context.Load($AssociatedMember)
$context.ExecuteQuery()
$web.AssociatedMemberGroup.AllowMembersEditMembership = $false
$web.AssociatedMemberGroup.Update();
$web.Context.ExecuteQuery() Deleted
Oct 06, 2016I created a extention for that:
try
{
Web rootweb = ctx.Site.RootWeb;
ctx.Load(rootweb, w => w.MembersCanShare);
ctx.ExecuteQueryRetry();
SharingConfiguration sharingSettings = configurationData.ToConfigObject<SharingConfiguration>();
// Set MembersCanShare, default to false
rootweb.MembersCanShare = sharingSettings.Sharing.MembersCanShare ? sharingSettings.Sharing.MembersCanShare : false;
rootweb.Update();
ctx.Load(rootweb, w => w.AssociatedMemberGroup.AllowMembersEditMembership);
ctx.ExecuteQueryRetry();
// Set AllowMembersEditMembership, default to false
rootweb.AssociatedMemberGroup.AllowMembersEditMembership = sharingSettings.Sharing.AllowMembersEditMembership ? sharingSettings.Sharing.AllowMembersEditMembership : false;
rootweb.AssociatedMemberGroup.Update();
ctx.ExecuteQueryRetry();
ctx.Load(rootweb, w => w.RequestAccessEmail);
ctx.ExecuteQueryRetry();
rootweb.RequestAccessEmail = sharingSettings.Sharing.RequestAccessEmail;
rootweb.Update();
ctx.ExecuteQueryRetry();
}
catch (Exception ex)
{
TraceHelper.WriteErrorToListener("LogFile", ex.Message);
}- Nigel PriceOct 06, 2016Iron Contributor
Is this for SharePoint On-Line or SharePoint On-Premises ? Or Both ?
- DeletedOct 07, 2016
Hi Nigel,
my example could be used for both..
Kr,
Paul
- Russell GoveNov 16, 2017Iron Contributor
Hi,
So there is no support for this in PNP-Powershell or the provisioning engine right now?
Russell
- Oct 06, 2016
Great replies of you all. Thanks! I'm sure I'll be able to generate a solution using your input next week. I'll update when I got it working.