我想使用PnP Powershell删除列表项的所有权限
我已经尝试过这个命令:
Set-PnPListItemPermission -Identity $item.id -User 'user@contoso.com' -AddRole "Contribute"
但是,运行脚本/命令的用户也被添加了完全控制权限。
是否有其他方法可以使用PnP Powershell删除列表项的所有现有权限?
谢谢
发布于 2021-01-20 10:39:33
我测试使用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
https://stackoverflow.com/questions/65798099
复制相似问题