Skip to content

Instantly share code, notes, and snippets.

@sionjlewis
Last active June 10, 2018 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionjlewis/292b2a6d5d52c60ccf4d97fb2704c8b2 to your computer and use it in GitHub Desktop.
Save sionjlewis/292b2a6d5d52c60ccf4d97fb2704c8b2 to your computer and use it in GitHub Desktop.
Microsoft Teams External Sharing with Anyone

_ReadMe.md

Troubleshooting

Run these commands individually if you are having trouble running the PowerShell scripts.

  1. Download SharePoint Online management Shell: https://www.microsoft.com/en-us/download/details.aspx?id=35588

  2. SharePoint Online Client Components SDK: https://www.microsoft.com/en-nz/download/details.aspx?id=42038

  3. Opening the PowerShell Console using "Run as Administrator"

  4. Check and set your Execution Policy

    Get-ExecutionPolicy;
    Set-ExecutionPolicy Unrestricted -Force;
    
  5. Install the PnP PowerShell modules https://github.com/SharePoint/PnP-PowerShell or look at: https://www.powershellgallery.com/packages/SharePointPnPPowerShellOnline/

    Install-Module SharePointPnPPowerShellOnline -AllowClobber;
    Update-Module SharePointPnPPowerShell*;
    Get-Module SharePointPnPPowerShell* -ListAvailable | Select-Object Name,Version | Sort-Object Version -Descending;
    

Uninstall PnP PowerShell modules

Use this Command to see multiple versions and only want one...

Uninstall-Module SharePointPnPPowerShellOnline -AllVersions -Confirm;
Get-Command -Module *PnP*;

Confirm PS Version

Run to confirm PS Version

$PSVersionTable.PSVersion;
# ======================================================================================================
# .\ModernSiteSettings.ps1
# ------------------------------------------------------------------------------------------------------
# Modified by: Siôn Lewis
# Modified Date: 10/06/2018
# ------------------------------------------------------------------------------------------------------
# https://docs.microsoft.com/en-us/powershell/module/sharepoint-online/set-sposite?view=sharepoint-ps
# https://docs.microsoft.com/en-us/powershell/module/sharepoint-pnp/set-pnptenant?view=sharepoint-ps
# ------------------------------------------------------------------------------------------------------
# Trouble shooting: _ReadMe.md
# ======================================================================================================
<#
cd "C:\Users\user.name\Desktop\";
.\ModernSiteSettings.ps1 -tenantAdminUrl "https://tenant-admin.sharepoint.com" -siteCollectionAdminUId "admin@tenant.co.nz";
#>
# ======================================================================================================
Param(
[string]$tenantAdminUrl,
[string]$siteCollectionAdminUId,
[string]$modernSiteUrl
)
# --------------------------------------------
# Helper Functions
# --------------------------------------------
function PromtForYesNo([string]$Message) {
$Prompt = Read-host ("{0} Y|N" -f $Message);
switch ($Prompt) {
Y { return $true; }
N { return $false; }
Default { PromtForYesNo -Message $Message; }
}
}
# --------------------------------------------
# Main Functions
# --------------------------------------------
#
# Set-SPOSharingCapability -TenantAdmCreds $tenantAdmCreds -TenantAdminUrl $tenantAdminUrl -SiteUrl "https://tenant.sharepoint.com/sites/ExternalSharing" -SharingCapability ExternalUserAndGuestSharing;
# ------------------------------------------------------------------------------------------------------
# Determines what level of sharing is available for the site. The possible values are:
# - ExistingExternalUserSharingOnly - (DEFAULT) Allow sharing only with the external users that already exist in your organization’s directory.
# - Disabled - External user sharing (share by email) and guest link sharing are both disabled.
# - ExternalUserSharingOnly - External user sharing (share by email) is enabled, but guest link sharing is disabled.
# - ExternalUserAndGuestSharing - External user sharing (share by email) and guest link sharing are both enabled.
#
function Set-SPOSharingCapability([object]$TenantAdmCreds, [string]$TenantAdminUrl, [string]$SiteUrl, [string]$SharingCapability) {
# Connect to SharePoint Online (not using PnP).
Connect-SPOService -url $TenantAdminUrl -credential $TenantAdmCreds;
# Enable External User and Guest Sharing on that chosen Site Collection.
Set-SPOSite -Identity $SiteUrl -SharingCapability $SharingCapability;
# Disconnect from SharePoint Online (not using PnP).
Disconnect-SPOService;
# Now check your work (refresh the page/site collection).
$yesNoMsgOpenSite = ("Open the Microsoft Team Site '{0}'?" -f $SiteUrl);
$responseOpenSite = PromtForYesNo -Message $yesNoMsgOpenSite;
if ($responseOpenSite) {
Start-Process -FilePath Chrome -ArgumentList $SiteUrl;
}
}
#
# Set-SharingCapability -TenantAdmCreds $tenantAdmCreds -TenantAdminUrl $tenantAdminUrl -SiteUrl "https://tenant.sharepoint.com/sites/ExternalSharing" -SharingCapability ExternalUserAndGuestSharing;
# ------------------------------------------------------------------------------------------------------
# Determines what level of sharing is available for the site. The possible values are:
# - ExistingExternalUserSharingOnly - (DEFAULT) Allow sharing only with the external users that already exist in your organization’s directory.
# - Disabled - External user sharing (share by email) and guest link sharing are both disabled.
# - ExternalUserSharingOnly - External user sharing (share by email) is enabled, but guest link sharing is disabled.
# - ExternalUserAndGuestSharing - External user sharing (share by email) and guest link sharing are both enabled.
#
function Set-SharingCapability([object]$TenantAdmCreds, [string]$TenantAdminUrl, [string]$SiteUrl, [string]$SharingCapability) {
# Connect to SharePoint Online (using PnP).
Connect-PnPOnline –Url $TenantAdminUrl -credential $TenantAdmCreds;
# Enable External User and Guest Sharing on that chosen Site Collection.
Set-PnPTenantSite -Url $SiteUrl -Sharing $SharingCapability;
# Disconnect from SharePoint Online (using PnP).
Disconnect-PnPOnline;
# Now check your work (refresh the page/site collection).
$yesNoMsgOpenSite = ("Open the Microsoft Team Site '{0}'?" -f $SiteUrl);
$responseOpenSite = PromtForYesNo -Message $yesNoMsgOpenSite;
if ($responseOpenSite) {
Start-Process -FilePath Chrome -ArgumentList $SiteUrl;
}
}
# --------------------------------------------
# Initialisation Code
# --------------------------------------------
[object]$tenantAdmCreds = Get-Credential -UserName $siteCollectionAdminUId -Message "Please enter Site Collection Admin credentials";
# Enable Anyone (anonymous access).
Set-SharingCapability -TenantAdmCreds $tenantAdmCreds -TenantAdminUrl $tenantAdminUrl -SiteUrl "https://tenant.sharepoint.com/sites/ExternalSharing" -SharingCapability ExternalUserAndGuestSharing;
# Disable Anyone (anonymous access).
#Set-SharingCapability -TenantAdmCreds $tenantAdmCreds -TenantAdminUrl $tenantAdminUrl -SiteUrl "https://tenant.sharepoint.com/sites/ExternalSharing" -SharingCapability ExistingExternalUserSharingOnly;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment