当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] 为 SharePoint Online 和 OneDrive for Business 设置匿名链接过期设置

作者:精品下载站 日期:2024-12-14 14:44:26 浏览:15 分类:玩电脑

为 SharePoint Online 和 OneDrive for Business 设置匿名链接过期设置


要求:为 SharePoint Online 和 OneDrive 配置匿名链接过期。

如何在 SharePoint Online 和 OneDrive 中设置匿名链接的过期时间?

匿名链接过期是 SharePoint Online 中的安全最佳实践,这允许 SharePoint Online 管理员设置通过匿名共享链接共享的项目的最长过期持续时间。您可以在租户级别设置 SharePoint Online 来宾链接过期时间。这可确保外部用户只能在有限的时间内访问共享内容,并防止意外或恶意共享链接时发生未经授权的访问。

要设置任何人链接的到期天数,请按照下列步骤操作:

  1. 登录 SharePoint 管理中心。
  2. 单击“策略”>>“共享”>>勾选“这些链接必须在这些天内过期”旁边的复选框,并设置访客链接可以处于活动状态的天数。例如,30
  3. 单击页面底部的“保存”以保存更改。

[玩转系统] 为 SharePoint Online 和 OneDrive for Business 设置匿名链接过期设置

这会在租户级别强制执行匿名链接的强制到期日期,并确定匿名共享链接的生命周期。如果您不设置这些到期天数:默认为 730 天(2 年!这是您可以设置的最大天数!)

PowerShell 在 SharePoint Online 中设置匿名链接过期:

打开 SharePoint Online Management Shell 并运行此 PowerShell 脚本以在 SharePoint Online 中配置来宾链接过期。


#SharePoint Admin Center URL
$AdminCenterURL = "https://Crescent-admin.sharepoint.com"

#Connect to SharePoint Online
Connect-SPOService -URL $AdminCenterURL -Credential (Get-Credential)

#Set Expiration Days for Anonymous links
Set-SPOTenant -RequireAnonymousLinksExpireInDays 30

现在,当您尝试共享匿名链接时,链接到期天数将默认设置为 30(或您配置的任何值)。您可以通过提供比租户级别配置的值短一天的时间来更改到期日期。不过,您设置的到期日期不能超出您在 SharePoint Online 管理中心的上述 PowerShell 脚本中设置的限制!这会使链接在配置的一定天数后失效。

[玩转系统] 为 SharePoint Online 和 OneDrive for Business 设置匿名链接过期设置

如果您尝试将链接到期日期更改为超出设置的限制,您将收到错误“您的组织的政策不允许链接保持活动状态超过 30 天。”此到期日设置适用于 SharePoint Online 和 OneDrive,从而最大限度地降低安全风险。

使用 PowerShell CSOM 配置匿名链接过期天数设置


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\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/"
$DaysToExpire = 7

#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 Anonymous Link Expiration Days Settings
    $Tenant.RequireAnonymousLinksExpireInDays= $DaysToExpire
    $Ctx.ExecuteQuery()

    Write-host "Anonyous Links Expiration Settings Updated Successfully!'" -f Green
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}
链接永不过期?
如果您不想让匿名链接过期,请将天数设置为“0”!

在网站集级别设置匿名链接的过期天数:

还可以在站点级别设置链接过期天数。这是 PowerShell 脚本:


#connect to SharePoint Online tenant Admin
Connect-SPOService -Url https://crescent-admin.sharepoint.com

#Set Link Expiration
Set-SPOSite -Identity https://crescent.sharepoint.com/sites/marketing -OverrideTenantAnonymousLinkExpirationPolicy $true -AnonymousLinkExpirationInDays 15

此 PowerShell 会使用您指定的设置覆盖租户级别设置。如果您想恢复为租户设置,请使用以下命令:


Set-SPOSite -Identity https://crescent.sharepoint.com/sites/marketing -OverrideTenantAnonymousLinkExpirationPolicy $false -AnonymousLinkExpirationInDays 0 

PnP PowerShell 设置链接过期策略

以下是使用 Set-PnPTenant 和 Set-PnPTenantSite cmdlet 在租户和站点级别设置链接过期设置的 PnP PowerShell:


#Connect to the Tenant
Connect-PnPOnline -Url "https://crescent-admin.sharepoint.com" -Interactive

#Set Tenant Level Link Expiry
Set-PnPTenant -RequireAnonymousLinksExpireInDays 30 

#Set Site Level Expiration Policy
Set-PnPTenantSite -Identity "https://crescent.sharepoint.com/sites/retail" -AnonymousLinkExpirationInDays 30

设置过期日期后,任何人链接将在指定时间自动过期,外部用户将无法再访问共享内容。

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯