How to Enable External Sharing in SharePoint Online?

Requirement: Enable external sharing in SharePoint Online using PowerShell

SharePoint Online allows you to collaboratively share your content with external users such as vendors, clients, customers, etc. To enable external sharing, you should turn on external sharing both on tenant level as well as on site collection level.

External Sharing settings in SharePoint Online offers below options:
  • Don't allow sharing outside your organization - disable external sharing!
  • Allow sharing only with the external users that already exist in your organization's directory.
  • Allow external users who accept sharing invitations and sign in as authenticated users.
  • Allow sharing with all external users, and by using anonymous access links.

How to Enable External Sharing in SharePoint Online?
To turn on external sharing in SharePoint online, follow these steps:
  • Open SharePoint Online Admin Center (Typically: https://TENANT-admin.sharepoint.com)
  • Click on "Sharing" from left navigation.
  • Under "Sharing outside your organization", set the sharing option to "Allow users to invite and share with authenticated external users" for better security.
  • Click on "OK" button in the bottom to save your changes.
    enable external sharing in sharepoint online
That's all! External Sharing is now turned on. There are additional settings in Sharing page such as: Default link type, Limit external sharing using domains, External users must accept sharing invitations using the same account that the invitations were sent to, etc which are self-explanatory. We can allow external sharing in SharePoint online using PowerShell as well.

SharePoint Online: How to Enable External Sharing using PowerShell?
To enable external sharing in SharePoint Online using PowerShell, use the below script:
#Set Admin Center URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Enable external sharing for the tenant
Set-SPOTenant -SharingCapability ExternalUserSharingOnly # Disabled, ExistingExternalUserSharingOnly, ExternalUserSharingOnly, ExternalUserAndGuestSharing

Allow External Sharing in SharePoint Online using PowerShell
You can also enable external sharing settings of the tenant using CSOM:
#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.SharePoint.Client.Runtime.dll"
Add-Type -Path "C:\Program Files\SharePoint Online Management Shell\Microsoft.Online.SharePoint.PowerShell\Microsoft.Online.SharePoint.Client.Tenant.dll"

#Variables for processing
$AdminCenterURL="https://crescent-admin.sharepoint.com"
$SharingCapability="ExternalUserAndGuestSharing"  # Disabled, ExistingExternalUserSharingOnly, ExternalUserSharingOnly, ExternalUserAndGuestSharing

#Get Credentials to connect
$Cred = Get-Credential

#Setup the Context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($AdminSiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
  
#Get the tenant object 
$Tenant = New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
  
#Set Sharing capability of the tenant
$Tenant.SharingCapability= [Microsoft.Online.SharePoint.TenantManagement.SharingCapabilities]::$SharingCapability
$Ctx.ExecuteQuery()

Write-host "Sharing Settings updated!"

Enable External Sharing in SharePoint Online Site Collection
Turning ON External sharing at the tenant level doesn't automatically turns ON Sharing capabilities at all underlying site collections! We need to enable sharing at each individual SharePoint Online site collection. From the SharePoint Admin Center, You can set the sharing settings for any site collection. To enable external sharing at site collection level using new SharePoint Online admin center, follow these steps:
  • Go to SharePoint Online Admin Center >> Select the desired Site collection from the list
  • Click on "Sharing" button >> Set the sharing settings appropriately, such as "New and existing external users". Click on "Save" to commit your changes.
    enable external sharing sharepoint online site collection
Please note, the site collection's sharing setting must be less permissive than your tenant settings!

Allow External Sharing in SharePoint Online Site Collection using PowerShell:
To activate external sharing for SharePoint Online site collection, use this PowerShell script.
#Variables for Admin Center & Site Collection URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
$SiteCollURL="https://crescent.sharepoint.com/Sites/Sales"

#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)

#Enable external sharing for the site collection
Set-SPOSite -Identity $SiteCollURL -SharingCapability ExternalUserSharingOnly

#Other Options: Disabled, ExistingExternalUserSharingOnly, ExternalUserSharingOnly, ExternalUserAndGuestSharing

This script turns on external sharing in SharePoint Online and sets the sharing option as same as the above screenshot! Running this command will enable external user and guest sharing in a SPO site collection and you can verify that in the screenshot below.

To get the list of all SharePoint Online Sites where sharing capability has been enabled:
Get-SPOSite | Where {$_.SharingCapability -ne "Disabled"}
How to Enable External Sharing in SharePoint Online? How to Enable External Sharing in SharePoint Online? Reviewed by Salaudeen Rajack on April 24, 2017 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.