Configure sharing on your SharePoint Site

SharePoint sites have by default the possibility to be shared by any member belonging to the site and with it, they can share with anyone of your organization or external. With this, you can end with the site being shared with a lot of users without you realizing that happened.

Today, we will explain how to disable/enable the sharing of a site on your SharePoint Online using the PowerShell. Note that you need to be Admin of the site collection to be able to change this setting.  After this setting is changed, the owners of the site will receive an email to allow or not the new user.

Connect-PnPOnline -Url https://contoso.sharepoint.com/sites/contoso

$ReadHost = Read-Host "Do you want to disable the share for the members of the Site? (y|n)"
if($ReadHost -match 'y'){
 $value = $false
}else{
 $value = $true
}

$Web = Get-PnPWeb
$context = Get-PnPContext
$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()
Write-Host "Done" -BackgroundColor Green -ForegroundColor Black

Conclusion

After you run this script the member of the site will no longer be able to share the site. I believe this option to share or not, it’ll always depend on the purposes of the site. I strongly recommend reading the blogs below which have more information about doing this on SharePoint interfaces and also their thoughts about this.

References

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *