SharePoint中用Power shell命令设置文档库列表的权限

首先停止继承权限

$web = Get-PnPweb
$spoList= Get-PnPList "Testlist" -Web $web (注释:获取对象)
$spoList.BreakRoleInheritance($true, $true)(注释:停止继承)
$spoList.Update()(注释:标记)

$spoList.Context.Load($spoList)(注释:)
$spoList.Context.ExecuteQuery() (执行)

 

--利用excel表格批量列表停止继承权限

$web = Get-PnPWeb
$filename="C:\Users\bobo\Desktop\list.csv"
ConvertFrom-Csv (gc $filename) | ForEach-Object{
$currentList=Get-PnPList $_.Name -Web $web
$currentList.BreakRoleInheritance($true, $true)
$currentList.Update()
$currentList.context.Load($currentList)
}
$web.context.ExecuteQuery()

 list.csv附件地址:https://files-cdn.cnblogs.com/files/xingyunqiu/list.zip

 

--利用筛选条件批量停止继承权限

我是利用“创建时间”进行筛选的

$web = Get-PnPWeb 
Get-PnPList | Where-Object "Created" -GE 2018-12-17|ForEach-Object{      
      $_.BreakRoleInheritance($true, $true)
      $_.Update()
      $_.context.Load($_)     
} 
$web.context.ExecuteQuery()

 

设置列表文档库单个用户的权限

Set-PnPListPermission -Identity '测试文档库' -User 'yuancb@kfgs.com.cn' -AddRole '读取'

设置单个列表的用户组权限

Set-PnPListPermission -Identity '测试文档库' -Group "读取权限组" -AddRole '读取'

对多个列表设置列表单个人或单个组的权限

$filename="C:\Users\bobo\Desktop\list.csv"
ConvertFrom-Csv (gc $filename) | ForEach-Object{
      Set-PnPListPermission -Identity $_.Name -Group "读取权限组" -AddRole '读取'
     }

 

posted @ 2018-12-14 17:57  幸运球与倒霉蛋  阅读(319)  评论(0编辑  收藏  举报