SharePoint Online: PowerShell to Get External Sharing Settings
Requirement: Find all site collections with external sharing enabled (or disabled!).
How to Check If External Sharing is Enabled in SharePoint Online Site?
As an administrator, you may need to audit External Sharing settings for a particular site (Or all sites!). This blog post will show you how to get external sharing settings in SharePoint Online from Admin Center. Furthermore, we’ll see how to use PowerShell to get External Sharing settings for SharePoint Online sites.
To check the external sharing settings of a site collection, follow these steps:
- Login to SharePoint Online Admin Center >> Click on the “Sites” link from the left navigation.
- Select the site from the site’s list, and click on the “Sharing” button in the toolbar. The sharing page displays the external sharing settings of the current site.
The settings denote these things:
- Anyone – External user sharing (share by email) and guest link sharing are enabled
- New and Existing Users – External user sharing (share by email) is enabled, but guest link sharing is disabled
- Existing External Users – Allow sharing only with external users that already exist in the organization’s directory (Default Setting)
- Only people in current organization – external user sharing (share by email) and guest link sharing – both are disabled
PowerShell to Get External Sharing Configuration in SharePoint Online:
The external sharing (or guest sharing) feature in SharePoint Online enables users to share documents and content outside the organization with people who are not members of your organization, such as external vendors, customers, consultants, etc.
SharePoint Online: PowerShell to List External Sharing
While External sharing settings at the tenant level can be configured using the links provided at the bottom of this article, We can check external sharing settings for all site collections levels using this PowerShell script in SharePoint Online Management Shell:
#Config Variables
$AdminSiteURL= "https://crescent-admin.sharepoint.com"
#Connect to SharePoint Online services
Connect-SPOService -url $AdminSiteURL -Credential (Get-Credential)
#Get External Sharing Settings for all sites
Get-SPOSite | Select-object url,sharingcapability
Similarly, we can get all Site collections where external sharing is enabled, as:
#Get All Site Collections with External Sharing Enabled
$Sites = Get-SPOSite -IncludePersonalSite $False | where {$_.SharingCapability -ne "Disabled"}
#Get URL of each site
Foreach ($Site in $Sites)
{
Write-Host $Site.Url
}
PnP PowerShell to Check External Sharing Settings for All Site Collections
Let’s get external sharing settings for all sites in the tenant and export them to a CSV file.
#Parameters
$Domain = "crescentintranet" #Domain Name in SharePoint Online. E.g. https://Crescent.sharepoint.com
$CSVFile = "C:\Temp\ExternalSharing.csv"
#Frame Tenant URL and Tenant Admin URL
$TenantURL = "https://$Domain.SharePoint.com"
$TenantAdminURL = "https://$Domain-Admin.SharePoint.com"
#Connect to Admin Center
Connect-PnPOnline -Url $TenantAdminURL -Interactive
#Get All Site collections - Filter BOT and MySite Host
$Sites = Get-PnPTenantSite -Filter "Url -like '$TenantURL'"
#Export External Sharing settings to CSV
$Sites | Select URL, SharingCapability
$Sites | Select URL, SharingCapability | Export-CSV $CSVFile -NoTypeInformation
Related Posts: