Tuesday, March 26, 2019

Change External Sharing Settings Across a Hub Site with PowerShell

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 Absolute SharePoint Blog 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.

The post Change External Sharing Settings Across a Hub Site with PowerShell appeared first on Absolute SharePoint Blog by Vlad Catrinescu.


by Vlad Catrinescu via Absolute SharePoint Blog by Vlad Catrinescu

No comments:

Post a Comment