如何在 SharePoint Online 中启用外部共享?
要求:使用 PowerShell 在 SharePoint Online 中启用外部共享。
如何在 SharePoint Online 中启用外部共享?
SharePoint Online 允许您与外部用户(例如供应商、客户、客户、顾问等)协作共享内容。要启用外部共享,您应该在租户级别和网站集级别(从管理中心或使用 PowerShell。在本文中,我们将向您展示如何在 SharePoint Online 中启用外部共享,以便您可以与组织外部的人员共享您的文档和文件:
SharePoint Online 中的外部共享设置提供以下选项:
- 仅限您组织中的人员 - 禁用外部共享!
- 现有访客 - 仅允许与组织目录中已存在的外部用户共享。
- 新来宾和现有来宾 - 允许接受共享邀请并以经过身份验证的用户身份登录的外部用户(Microsoft 帐户或学校帐户/工作帐户来访问共享项目)。
- 任何人 - 允许与所有外部用户共享,包括匿名访问链接。
步骤 1:在租户处启用外部共享
要在 SharePoint Online 租户中打开外部共享,请执行以下步骤:
- 以全局管理员或 SharePoint 管理员身份登录并打开 SharePoint Online 管理中心(通常位于:https://
)-admin.sharepoint.com - 单击左侧导航栏中的策略>>共享
- 在“外部共享”设置下,将共享选项设置为“新来宾和现有来宾”以提高安全性。您可以为 SharePoint 和 Microsoft OneDrive 选择任何适当的组织级别共享设置。
单击底部的“确定”按钮保存更改。
就这样!外部共享现已开启。共享页面上的“更多外部共享设置”下还有其他设置,例如,使用域限制外部共享、外部用户必须使用与邀请发送到的同一帐户接受共享邀请等,我们还有“文件”和文件夹链接”不言自明的设置。例如,共享链接设置默认为“特定人员”、“任何人”链接的到期时间、默认链接类型等。
我们还可以使用 PowerShell 在 SharePoint Online 中允许外部共享。以下是如何使用 PowerShell 在 SharePoint Online 中配置共享功能:
SharePoint Online:如何使用 PowerShell 启用外部共享?
为了与组织外部的人员协作,您需要与外部共享您的文档和内容。如何使用 PowerShell 在 SharePoint Online 中启用外部共享?要在 SharePoint Online 中启用外部共享,请使用以下 PowerShell 脚本:
#Set Admin Center URL
$AdminCenterURL = "https://crescent-admin.sharepoint.com/"
#Connect to SharePoint Online
Connect-SPOService -url $AdminCenterURL -Credential (Get-Credential)
#sharepoint online enable external sharing powershell
Set-SPOTenant -SharingCapability ExternalUserSharingOnly # Disabled, ExistingExternalUserSharingOnly, ExternalUserSharingOnly, ExternalUserAndGuestSharing (Anonymous sharing)
上述脚本的 PnP PowerShell 版本为:
#Parameters
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
#Connect to Tenant Admin Site
Connect-PnPOnline -url $TenantAdminURL -Interactive
#Enable External Sharing for the Tenant to - Anyone - Anonymous users
Set-PnPTenant -SharingCapability ExternalUserAndGuestSharing
允许使用 PowerShell 在 SharePoint Online 中进行外部共享
您还可以在租户级别启用外部共享设置。以下是如何使用 PowerShell 在 SharePoint Online 中打开外部共享:
#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="ExternalUserSharingOnly" # 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!"
让我们设置外部共享以允许访客用户和匿名链接:
#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"
#Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SharingCapability="ExternalUserAndGuestSharing" #File and folder links
$DaysToExpire = 7 #Expiration number of days for shared files
$LinkType="View" #Edit, View or None
$FolderLinkType="Edit" # View or Edit or None
#Get Credentials to connect
$Cred= Get-Credential
Try {
#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
$Tenant= New-Object Microsoft.Online.SharePoint.TenantAdministration.Tenant($Ctx)
$Ctx.Load($Tenant)
$Ctx.ExecuteQuery()
#Set Tenant Sharing Settings
$Tenant.SharingCapability= [Microsoft.Online.SharePoint.TenantManagement.SharingCapabilities]::$SharingCapability
$Tenant.RequireAnonymousLinksExpireInDays= $DaysToExpire
$Tenant.FileAnonymousLinkType=[Microsoft.SharePoint.Client.AnonymousLinkType]::$LinkType
$Tenant.FolderAnonymousLinkType=[Microsoft.SharePoint.Client.AnonymousLinkType]$FolderLinkType
$Ctx.ExecuteQuery()
Write-host "Tenant Sharing Settings Updated Successfully!'" -f Green
}
Catch {
write-host -f Red "Error:" $_.Exception.Message
}
这将导致 SharePoint Online 租户中的以下设置。
步骤 2:在 SharePoint Online 网站集中启用外部共享
在租户级别打开外部共享不会自动在所有基础网站集中打开共享功能!我们需要在每个 SharePoint Online 网站集上启用共享。您可以从 SharePoint 管理中心设置任何网站集的共享设置。要使用新的 SharePoint Online 管理中心允许在网站集级别进行外部共享,请执行以下步骤:
- 转到 SharePoint Online 管理中心 >> 单击站点 >> 活动站点 >> 从列表中选择所需的网站集。
-
单击“共享”按钮>>适当设置共享设置,例如“新的和现有的外部用户”。单击“保存”以提交您的更改。
请注意,网站集的共享级别必须等于或低于您的组织级别设置!例如,如果您将租户级别设置设置为“现有外部用户”,则 SharePoint 设置可以应用于“现有外部用户”或以下。
允许使用 PowerShell 在 SharePoint Online 网站集中进行外部共享
要激活 SharePoint Online 网站级别的外部共享,请使用此 PowerShell 脚本。
#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
使用 PnP PowerShell 在 SharePoint Online 中启用外部用户
要在 SharePoint Online 中启用外部共享特定网站集,请使用此 PnP PowerShell:
#Parameters
$TenantAdminURL = "https://crescent-admin.sharepoint.com"
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
#Connect to Tenant Admin Site
Connect-PnPOnline -url $TenantAdminURL -Interactive
#Enable External Sharing for Existing AD Users (Including Guest users!)
Set-PnPTenantSite -Url $SiteURL -SharingCapability ExistingExternalUserSharingOnly
此脚本在 SharePoint Online 中打开外部共享,并将共享选项设置为与上面的屏幕截图相同!运行此命令将在 SPO 网站集中启用外部用户和来宾共享,您可以在管理中心进行验证。
为租户中的所有站点设置外部共享设置
如何在 SharePoint Online 租户中的所有网站集上应用特定的外部共享设置?
#Parameters
$AdminCenterURL="https://crescent-admin.sharepoint.com"
$ExternalSharingSetting = "ExternalUserAndGuestSharing" #Anyone
Try {
#Connect to Admin center
Connect-PnPOnline -URL $AdminCenterURL -Interactive
#Get all sites where the setting is different from the given parameter - Exclude Seach Center, Redirect sites, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bots
$SiteCollections = Get-PnPTenantSite | Where { $_.URL -like '*/sites*' -and $_.SharingCapability -ne $ExternalSharingSetting -and $_.Template -NotIn `
("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")}
#Loop through each site and enable external sharing
ForEach ($Site in $SiteCollections)
{
#Apply External sharing setting for the site
Set-PnPTenantSite -Url $Site.Url -SharingCapability $ExternalSharingSetting
Write-host "External sharing Setting updated for:" $Site.URL -f Green
}
}
Catch {
Write-host -f Red "Error:" $_.Exception.Message
}
要获取已启用共享功能的所有 SharePoint Online 网站的列表:
Get-SPOSite | Where {$_.SharingCapability -ne "Disabled"}
这是禁用外部共享的另一篇文章:SharePoint Online:PowerShell 禁用外部共享
结论
总之,在 SharePoint Online 中启用外部共享是一个简单的过程,可以通过导航到 SharePoint 管理中心并调整共享设置来完成。此外,通过为特定站点配置外部共享设置,管理员可以更好地控制内容的共享方式和对象。总体而言,SharePoint Online 中的外部共享是一项强大的功能,允许组织与合作伙伴、客户和其他外部利益相关者协作和共享信息。
经常问的问题:
如何在 SharePoint Online 中添加除外部用户之外的所有人?
启用“除外部用户之外的所有人”声明,然后您可以将除外部用户之外的所有人添加到 SharePoint Online。
详细信息:向 SharePoint Online 中除外部用户组之外的所有人授予访问权限
如何从 SharePoint Online 中删除外部用户?
您可以使用 PowerShell cmdlet Remove-SPOExternalUser 从 SharePoint Online 网站中删除外部用户。
详细信息:从 SharePoint Online 中删除外部用户
如何在 SharePoint Online 中向外部用户提供访问权限?
假设已启用外部共享,请按照以下步骤为 SharePoint 网站上的外部用户提供访问权限: 登录到您的 SharePoint Online 网站 >> 单击页面右上角的“共享”按钮。输入外部用户的电子邮件,确保选中“发送电子邮件”复选框,然后单击底部的“共享”按钮。
更多信息:向 SharePoint Online 中的外部用户授予访问权限
如何启用 OneDrive 外部共享?
要启用 OneDrive 的外部共享:在 SharePoint 管理中心上,展开“策略”,然后单击左侧导航中的“共享”链接。在“外部共享”下,将配置设置为“仅限组织中的人员”以外的任何内容。
详细信息:使用 PowerShell 在 OneDrive for Business 中启用外部共享


