15 49.0138 8.38624 1 0 4000 1 https://vladtalkstech.com 300 1
theme-sticky-logo-alt

Change External Sharing Settings Across a Hub Site with PowerShell

1 Comment

One of the big Information Architecture changes with modern SharePoint is the flat architecture, which means that now, instead of your Intranet being one Site Collection with multiple subsites, it will now be multiple Site Collections. I’ve seen multiple example architectures where an Intranet can easily become over 15 Site Collections! That means, each Site Collection has its own settings, including external access! While a new SharePoint Admin Center is shipping, you cannot bulk-change External Sharing settings.

So I have built a quick PowerShell script that you can simply provide the URL of a Hub Site and the level of external sharing you want to enable, and it will do the magic for you! The script seen below requires two parameters, and it has some validations in to make sure you supply the right type of values.

  1. HubSiteUrl : The URL of a Hubsite
  2. ExternalSharing : one of the following options:
    1. Disabled – don’t allow sharing outside your organization
    2. ExistingExternalUserSharingOnly – Allow sharing only with the external users that already exist in your organization’s directory
    3. ExternalUserSharingOnly – allow external users who accept sharing invitations and sign in as authenticated users
    4. ExternalUserAndGuestSharing – allow sharing with all external users, and by using anonymous access links.

If you examine the script, you will realize that I run the Get-SPOSite twice , that is because when you run Get-SPOSite without specifying a URL , it doesn’t return the HubSiteId , so that’s why we have to do it!

Download the following script and save it as HubExternal.ps1.

param 
( 
    [Parameter(Mandatory=$true)]
    [string]$HubSiteUrl, 
    [Parameter(Mandatory=$true)][ValidateSet("Disabled","ExistingExternalUserSharingOnly","ExternalUserSharingOnly","ExternalUserAndGuestSharing")]
    [String]$ExternalSharing
)

$HubId = (Get-SPOHubSite -ErrorAction SilentlyContinue | Where {$_.SiteUrl -eq $HubSiteURL}).Id.Guid
if ($HubId -eq $null)
{
	Throw "URL provided is not a valid Hub Site url"
}

$sites = Get-SPOSite -Limit All
foreach ($site in $Sites)
{
	$siteDetails = Get-SPOSite $site.Url
	If ($siteDetails.HubSiteId.Guid -eq $HubId)
		{
		Write-Host "Setting " $site.Url " external sharing permissions to " $ExternalSharing
		Set-SPOSite $siteDetails -SharingCapability $ExternalSharing
		}
}

Here is an example on how to run it:

.\HubExternal.ps1 -HubSiteUrl https://valo365.sharepoint.com/sites/contoso-work -ExternalSharing ExternalUserAndGuestSharing

And this is what it should look like when running it!

External Sharing Settings Across a Hub Site

I hope this helps! You can of course modify this script to take the same logic, and do a bunch of different changes on all the Site Collections in a certain Hub Site!

Leave a comment and don’t forget to like the Vlad Talks Tech Page   on Facebook and to follow me on Twitter here  for the latest news and technical articles on SharePoint.  I am also a Pluralsight author, and you can view all the courses I created on my author page.
Previous Post
Meet the Speaker series: Chris Kent
Next Post
Meet the Speaker series: Eric Overfield

1 Comment

  • November 4, 2019 at 6:00 pm

    I d like to remind you that when you are granting permissions to guests, you might also need to adjust the SharingCapability setting of the site before guests can access. I ve previously written a blog post about disabling guest access, but you can use those same scripts for enabling access too if it is not more restrictive on tenant level. Also remember that if your site is a modern team site, you most likely also want to adjust the external sharing setting for its Office 365 group, too.

    Reply

Leave a Reply