Oct 05 2016 09:34 AM
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 in the commands.
I mean changing the following setting(s) by PowerShell / remote provisioning:
Oct 06 2016 05:40 AM - edited Oct 06 2016 06:04 AM
Hello Harold,
Are you using SPO? This url might point you in the right direction regarding changing the setting programatically for SharePoint online:
https://blogs.msdn.microsoft.com/chandru/2015/12/31/sharepoint-onlinecsom-change-access-requests-set... (there is a comment with a suggestion to how this can be removed with powershell)
I have just started looking into this, so haven't tested this myself yet.
Let me know when you find a way to have this setting un-checked during site provisioning with PnP Provisioning Engine, as I am currently searching for that myself.
Oct 06 2016 05:47 AM
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()
Oct 06 2016 06:09 AM
I 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); }
Oct 06 2016 06:18 AM
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.
Oct 06 2016 09:01 AM
Is this for SharePoint On-Line or SharePoint On-Premises ? Or Both ?
Oct 06 2016 10:51 PM
Hi Nigel,
my example could be used for both..
Kr,
Paul
Nov 16 2017 11:34 AM
Hi,
So there is no support for this in PNP-Powershell or the provisioning engine right now?
Russell
Nov 16 2017 11:52 AM
Heres the equivalent powershell. This works in O365
function DisableMemberSharing($siteUrl ) {
Connect -Url $siteUrl
$web = Get-PnPWeb -Includes MembersCanShare, AssociatedMemberGroup.AllowMembersEditMembership
$web.MembersCanShare=$false
$web.AssociatedMemberGroup.AllowMembersEditMembership=$false
$web.AssociatedMemberGroup.Update()
$web.Update()
$web.Context.ExecuteQuery()
}
Mar 20 2018 03:25 AM
Hi,
Is there also a command to enable/disable the "Allow access requests" via powsershell?
Cheers
Jul 03 2018 05:46 AM
For SharePoint online you can try this:
Connect-PnPOnline -url https://contoso.sharepoint.com/sites/test
Set-PnPRequestAccessEmails -Emails " "
Jul 03 2018 07:19 AM
@Mani Mehrabi Thanks! I have tried the suggested but it does not work. In the Access Request Settings it seems MS has also added a new radio button for choosing either email or the Site owners.
Oct 22 2018 01:02 PM
I ran into this same problem. Try this:
$web = Get-PnPWeb -Includes MembersCanShare, AssociatedMemberGroup.AllowMembersEditMembership
$web.MembersCanShare=$false
$web.AssociatedMemberGroup.AllowMembersEditMembership=$false
$web.AssociatedMemberGroup.Update()
$web.RequestAccessEmail = $null
$web.Update()
$web.Context.ExecuteQuery()
Sep 16 2022 02:09 PM - edited Sep 16 2022 02:10 PM
Also an option:
Connect-PnPOnline -ClientId "<your Azure App Registration Client ID>" -Thumbprint "<your certificate thumbprint>" -Url "<your site URL>" -Tenant "<your Tenant name>.onmicrosoft.com"
$membersGroupID = (Get-PnPGroup -AssociatedMemberGroup).id
Set-PnPGroup -Identity $membersGroupID -AllowMembersEditMembership $false