【问题标题】:How to remove all list item permissions using PnP Powershell如何使用 PnP Powershell 删除所有列表项权限
【发布时间】:2021-04-24 03:25:13
【问题描述】:

我想使用 PnP Powershell 删除列表项的所有权限

我试过这个命令:

Set-PnPListItemPermission -Identity $item.id -User 'user@contoso.com' -AddRole "Contribute"

但是,运行脚本/命令的用户也被添加了完全控制权限。

有没有其他方法可以使用 PnP Powershell 删除列表项的所有现有权限?

谢谢

【问题讨论】:

    标签: powershell sharepoint permissions


    【解决方案1】:

    我测试在 PnP PowerShell 中使用读取权限用户连接到 SharePoint Online 网站,然后运行 ​​Set-PnPListItemPermission 命令,它会抛出拒绝访问错误,而不是添加完全控制权限:

    总而言之,要为列表项设置权限,运行脚​​本的用户需要在站点级别拥有完全控制权限。否则会抛出拒绝访问错误。

    完全控制权限应与站点组一起应用,在列表中,尝试打破权限继承并删除组:

    # Provide credentials over here
    $creds = (New-Object System.Management.Automation.PSCredential "<<UserName>>",(ConvertTo-SecureString "<<Password>>" -AsPlainText -Force))
     
    # Provide URL of the Site over here
    # If you do not wish to pass credentials hard coded then you can use: -Credentials (Get-Credential). This will prompt to enter credentials
    Connect-PnPOnline -Url http://MyServer/sites/MySiteCollection -Credentials $creds
     
    # Get Context
    $clientContext = Get-PnPContext
     
    $targetWeb = Get-PnPWeb
     
    # Get the list object
    $targetList = $targetWeb.Lists.GetByTitle("List Name")
     
    # Load List object
    $clientContext.Load($targetList)
    $clientContext.ExecuteQuery()
     
    # This method will work only if the role inheritence is broken(list has unique role assignments) on the list
    $targetList.RoleAssignments.Groups.RemoveByLoginName("test Visitors")
     
    $clientContext.ExecuteQuery()
     
    Disconnect-PnPOnline
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-27
      • 2015-09-07
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 2010-11-29
      • 1970-01-01
      相关资源
      最近更新 更多