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

[玩转系统] SharePoint Online:如何将列表设为只读?

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

SharePoint Online:如何将列表设为只读?


要求:将 SharePoint Online 列表设置为只读。

如何在 SharePoint Online 中将列表设置为只读?

在 SharePoint Online 中,您可能希望将列表设为只读以防止用户编辑或删除项目。如果您想发布列表作为参考或存档,这会很有用。本文将介绍可用于在 SharePoint Online 中使列表只读的选项。

没有直接的方法将 SharePoint Online 列表设置为只读。但是,我们可以按照此解决方法将列表设置为只读模式:

  1. 导航到您的 SharePoint Online 列表 >> 单击“设置”齿轮并选择“列表设置”
  2. 单击列表设置页面“权限和管理”组下的“此列表的权限”链接。
  3. 如果列表中尚未包含损坏的权限,请单击功能区中的“停止继承权限”按钮并确认提示。
  4. 选择具有读取以外权限的用户和组。例如,完全控制、编辑、贡献等,然后单击功能区中的“编辑用户权限”按钮。

    [玩转系统] SharePoint Online:如何将列表设为只读?

  5. 在编辑权限页面中,选择“读取”权限,然后单击“确定”,将所有人的权限重置为“读取”。

    [玩转系统] SharePoint Online:如何将列表设为只读?

PowerShell 将 SharePoint Online 中的列表设为只读

让我们自动执行上述步骤,将 SharePoint Online 列表或库设为只读!下面是用于设置权限的 PowerShell,以防止用户更改列表中的数据。


#Parameter
$SiteURL = "https://Crescent.sharepoint.com/sites/PMO"
$ListName= "Projects"
 
#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
 
#Get the Web and List
$Web = Get-PnPWeb
$List = Get-PnPList -Identity $ListName -Includes HasUniqueRoleAssignments, RoleAssignments

#Break Permissions of the List
If ($List.HasUniqueRoleAssignments -eq $False)
{
    Set-PnPList -Identity $ListName -BreakRoleInheritance -CopyRoleAssignments
}
 
#Get Read Permission Level
$ReadPermission = Get-PnPRoleDefinition -Identity "Read"

#Grant "Read" permissions, if its not granted already
$List.RoleAssignments | ForEach-Object {
    #Get the user or group of the assignment - Handle error for orphans
    $Member = Get-PnPProperty -ClientObject $_ -Property Member -ErrorAction SilentlyContinue

    If($Member.IsHiddenInUI -eq $False)
    {
        Get-PnPProperty -ClientObject $_ -Property RoleDefinitionBindings | Out-Null
 
        #Check if the current assignment has any permission other than Read or related
        $PermissionsToReplace = $_.RoleDefinitionBindings | Where {$_.Hidden -eq $False -And $_.Name -Notin ("Read", "Restricted Read", "Restricted Interfaces for Translation")}
        
        #Grant "Read" permissions, if its not granted already
        If($PermissionsToReplace -ne $Null)
        {
            $_.RoleDefinitionBindings.Add($ReadPermission)
            $_.Update()
            Invoke-PnPQuery
            Write-host "Added 'Read' Permissions to '$($Member.Title)'" -ForegroundColor Cyan
        }
    }
}
#Reload List permissions
$List = Get-PnPList -Identity $ListName -Includes RoleAssignments

#Remove All permissions other than Read or Similar
$List.RoleAssignments | ForEach-Object {
    #Get the user or group of the assignment - Handle error for orphans
    $Member = Get-PnPProperty -ClientObject $_ -Property Member #-ErrorAction SilentlyContinue | Out-Null    
    If($Member.IsHiddenInUI -eq $False)
    {
        Get-PnPProperty -ClientObject $_ -Property RoleDefinitionBindings | Out-Null
 
        $PermissionsToRemove = $_.RoleDefinitionBindings | Where {$_.Hidden -eq $False -And $_.Name -Notin ("Read", "Restricted Read", "Restricted Interfaces for Translation")}
        If($PermissionsToRemove -ne $null)
        {
            ForEach($RoleDefBinding in $PermissionsToRemove)
            {
                $_.RoleDefinitionBindings.Remove($RoleDefBinding)
                Write-host "Removed '$($RoleDefBinding.Name)' Permissions from '$($Member.Title)'" -ForegroundColor Yellow    
            }
            $_.Update()
            Invoke-PnPQuery
        }
    }
}
Write-host "List is set to Read-Only Successfully!" -f Green

此 PowerShell 脚本使用“读取”重置所有权限。请注意,这些方法不能控制网站集管理员!

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

取消回复欢迎 发表评论:

关灯