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?
To check the external sharing settings of a site collection,
  • Login to SharePoint Online Admin Center >> Click on "Sites" link from the left navigation
  • Select the site from sites list, click on the "Sharing" button in the toolbar. The sharing page displays the external sharing settings of the current site.
    sharepoint online check if external sharing is enabled
The settings denote these things:
  1. Anyone - External user sharing (share by email) and guest link sharing both enabled 
  2. New and Existing Users - External user sharing (share by email) enabled, but guest link sharing disabled
  3. Existing External Users - Allow sharing only with external users that already exist in the organization's directory (Default Setting)
  4. 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:
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 tenant level can be configured using links provided in the bottom of this article, We can check external sharing settings for all site collections level 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 it to CSV file.
#Parameters
$Domain =  "crescentintranet" #Domain Name in SharePoint Online. E.g. https://CrescentIntranet.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 -UseWebLogin

#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:

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.