SharePoint Online: How to Disable Sharing for Non-Owners using PowerShell?
Requirement: Disable Sharing for Non-Owners in SharePoint Online.
How to Disable Sharing for Members in SharePoint?
If you are a SharePoint Online administrator, You may want to disable sharing for people who are not site owners. Perhaps you have users who need access to specific content but don’t need the ability to share it with others. This article will show you how to disable sharing for non-owners in SharePoint Online (and the other way around: allow members to share the site and individual files and folders in SharePoint Online). We will also cover using PowerShell to prevent site members from sharing the site.
To disable sharing for members in SharePoint Online, follow these steps:
- Click on Settings >> Site Settings >> Site Permissions
- Click on the “Access Request Settings” button in the ribbon.
- Uncheck “Allow members to share the site and individual files and folders.”. You can also uncheck “Allow members to invite others to the site members group, <Group Name>. This setting must be enabled to let members share the site. “
This disables the share button for non-owners (members) for a given site. If you want to allow members to share the site and individual files and folders, just enable this checkbox.
In group connected modern sites, these settings are under Settings >> Site Permissions >> Change how members can share
PowerShell to Disable Sharing for Non-Owners
Here is the PowerShell to set sharing permissions to “Disable sharing for non-owners” in SharePoint Online:
#Config Variables $AdminSiteURL= "https://crescent-admin.sharepoint.com" $SiteURL= "https://crescent.sharepoint.com/sites/marketing" #Connect to SharePoint Online services Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential) #Disable Sharing for Non-Owners Set-SPOSite -Identity $SiteURL -DisableSharingForNonOwners
To allow members to share a SharePoint Online site using PnP PowerShell, you can use the following script:
#Parameters $SiteURL = "https://crescent.sharepoint.com/sites/marketing" #Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Disable Sharing permissions settings - Disable Sharing for Non Owners Set-PnPSite -Identity $SiteURL -DisableSharingForNonOwners
Found a problem, though! When you run this script for the first time, it disables access requests! Furthermore, I don’t find any PowerShell ways to reverse this as of today (Allow members to share!) To disable the share button in SharePoint Online, use: How to Disable Share Feature in SharePoint Online?
7 thoughts on “SharePoint Online: How to Disable Sharing for Non-Owners using PowerShell?”
Is it possible to achieve this via SharePoint API? We would like to implement it in a powerautomate workflow
I think it would be important to say that these settings in fact do NOT disable the share button. People will still be able to see and use the share button in doc libraries but they can only share with people that already have access anyway. Afaik there’s currently now way to actually hide / disable the share button, which is a bummer.
Thank you for this information.
Is there a way to let all users of a SharePoint site to share links with others who have permissions, but not outside of the membership?
we are finding when sharing links, that individual names are then added to the permissions list, when those people are already in a permission group for that library… gets messy, can’t seem to find a way to clean up the mess
try using this instead
$web = Get-PnPWeb -Includes MembersCanShare -Connection $webConn
$web.MembersCanShare = $membersCanShareValue
Looking for a way to set the site sharing permissions to Site Owners and Members, and people with edit but only site owners can share the site. Thank you
Is there any cmdlet to set this option to “Members can share files and folders, but NOT the whole site” ?
How to reverse this? I also want to be able to set the setting to “Sharing documents en folders, but not the site”.