简体   繁体   English

如何使用 PnP Powershell 删除所有列表项权限

[英]How to remove all list item permissions using PnP Powershell

I would like to remove all permissions of a list item using PnP Powershell我想使用 PnP Powershell 删除列表项的所有权限

I have tried this command:我试过这个命令:

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

However the user running the script/command was also added with Full Control permissions.然而,运行脚本/命令的用户也被添加了完全控制权限。

Is there any other way to remove all existing permissions for a list item using PnP Powershell?有没有其他方法可以使用 PnP Powershell 删除列表项的所有现有权限?

Thanks谢谢

I tested to connect to SharePoint Online site with a read permission user in PnP PowerShell and then run the Set-PnPListItemPermission command, it will throw Access Denied error instead of adding with Full Control Permissions:我测试连接到 SharePoint Online site with a read permission user in PnP PowerShell 然后运行 Set-PnPListItemPermission 命令,它会抛出拒绝访问错误,而不是添加完全控制权限:

在此处输入图像描述

In Summary, to set permssions for list item, it's expecetd to have the Full Control Permission on the site level for the user who is running the script.总之,要为列表项设置权限,运行脚本的用户需要在站点级别拥有完全控制权限。 Otherwise, the Access Denied error will throw.否则,将抛出拒绝访问错误。

The Full Control permissions should be applied with the site group, in the list, try to break permission inheritance and remove the group:完全控制权限应与站点组一起应用,在列表中,尝试打破权限 inheritance 并删除组:

# 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM