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

[玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

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

SharePoint Online:使用 PowerShell 禁用所有网站的访问请求


要求:禁用 SharePoint Online 网站的访问请求。

如何在 SharePoint Online 中禁用访问请求?

您可能希望在特定情况下禁用 SharePoint Online 中的访问请求。我们可以通过网站设置或使用 PowerShell 禁用人们请求访问您的 SharePoint Online 网站的能力。在这篇博文中,我们将介绍如何使用 PowerShell 禁用(或启用)SharePoint Online 中的用户访问请求。让我们开始吧!

要禁用 SharePoint Online 网站的访问请求,请执行以下操作:

  1. 转到您想要禁用访问请求的 SharePoint Online 网站。
  2. 单击右上角的“设置”齿轮图标,然后在下拉菜单中选择“站点权限”。
  3. 在“站点权限”面板上,单击“站点共享”下的“更改成员共享方式”链接。

    [玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

  4. 通过滑动旁边的按钮将“访问请求”设置切换为“关闭”。

    [玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

  5. 单击“保存”按钮以提交您的更改。

就这样!我们已禁用您网站的访问请求。这意味着如果用户没有权限,将无法请求访问资源。同样,在经典 SharePoint 网站(以及现代网站!)上,请按照以下步骤关闭访问请求。

  1. 单击设置齿轮>>站点权限>>访问请求设置。
  2. 这将带您进入网站的 SharePoint Online 访问请求设置页面。取消选中“允许访问请求”复选框,然后单击“确定”保存更改。

    [玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

这将禁用特定站点的访问请求。但是,访问请求设置的范围仅限于用户拥有唯一权限的每个站点。因此,如果您的子网站使用唯一权限,则必须对网站集中的每个子网站(或租户中的每个子网站!)重复上述步骤。让我们自动执行这些步骤以禁用网站集和租户级别的访问请求。

SharePoint Online:使用 PowerShell 禁用访问请求

使用 PnP PowerShell,我们可以禁用对给定 SharePoint Online 网站集的访问请求。


#Parameter
$SiteURL = "https://crescent.sharepoint.com/sites/Marketing"

#Function to disable access request on SharePoint Online Web
Function Disable-PnPAccessRequest
{ 
    [cmdletbinding()]
    Param(
        [parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
    )

    Try {
        Write-host -f Yellow "Disabling Access Request on:"$web.Url
        If($Web.HasUniqueRoleAssignments)
        {
            #Disable Access Request           
            $Web.RequestAccessEmail = [string]::Empty
            $Web.SetUseAccessRequestDefaultAndUpdate($False)
            $Web.Update()
            Invoke-PnPQuery
            Write-host -f Green "`tAccess Request has been Disabled!"$web.Url
        }
        else
        {
            Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url
        }
    }
    Catch {
        write-host "`tError Disabling Access Request: $($_.Exception.Message)" -foregroundcolor Red
    }
}

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Call the Function for all webs
Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments | ForEach-Object { Disable-PnPAccessRequest $_ }

如何禁用租户中所有站点的访问请求?

PowerShell 禁用租户中所有站点的访问请求

让我向您展示如何自动禁用租户中所有 SharePoint Online 网站中的访问请求。此 PowerShell 脚本会循环访问租户中的每个站点,并在站点使用唯一权限时关闭访问请求:


#Parameter
$TenantAdminURL = "https://Crescent-Admin.SharePoint.com"
 
#Function to disable access request on SharePoint Online Web
Function Disable-PnPAccessRequest
{ 
    [cmdletbinding()]
    Param(
        [parameter(Mandatory = $true, ValueFromPipeline = $True)] $Web
    )
 
    Try {
        Write-host -f Yellow "Disabling Access Request on:"$web.Url
        If($Web.HasUniqueRoleAssignments)
        {
            #Disable Access Request           
            $Web.RequestAccessEmail = [string]::Empty
            $Web.SetUseAccessRequestDefaultAndUpdate($False)
            $Web.Update()
            Invoke-PnPQuery
            Write-host -f Green "`tAccess Request has been Disabled!"$web.Url
        }
        else
        {
            Write-host -f Yellow "`tWeb inherits permissions from the parent!"$web.Url
        }
    }
    Catch {
        write-host "`tError Disabling Access Request: $($_.Exception.Message)" -foregroundcolor Red
    }
}
 
#Connect to Admin Center
$Cred = Get-Credential
Connect-PnPOnline -Url $TenantAdminURL -Credentials $Cred
  
#Get All Site collections - Exclude: Seach Center, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$SitesCollections = Get-PnPTenantSite | Where -Property Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")
  
#Loop through each site collection
ForEach($Site in $SitesCollections)
{
    #Connect to site collection
    Connect-PnPOnline -Url $Site.Url -Credentials $Cred
 
    #Call the Function for all webs
    Get-PnPSubWeb -IncludeRootWeb -Recurse -Includes HasUniqueRoleAssignments | ForEach-Object { Disable-PnPAccessRequest $_ }

}

在运行此脚本之前,请确保您有权访问租户中的所有站点!否则,您可能会收到“访问被拒绝”或“401 未经授权”错误!一旦访问请求被关闭,无权访问该网站的用户将看到此页面,

[玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

代替:

[玩转系统] SharePoint Online:使用 PowerShell 禁用所有网站的访问请求

结论

总之,在 SharePoint Online 中禁用访问请求是一个可由 SharePoint 管理员完成的简单过程。通过禁用访问请求,用户将无法再请求访问网站或文档库。相反,管理员需要手动向用户授予访问权限。当组织希望更严格地控制谁有权访问某些内容时,这可能很有用。禁用访问请求还消除了持续监视和批准访问请求的需要,这可以为管理员节省时间和资源。

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

取消回复欢迎 发表评论:

关灯