|
# ====================================================================================================== |
|
# .\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 "[email protected]"; |
|
#> |
|
# ====================================================================================================== |
|
|
|
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; |