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

[玩转系统] 使用 PowerShell 在 SharePoint 中复制列表权限

作者:精品下载站 日期:2024-12-14 20:59:38 浏览:13 分类:玩电脑

使用 PowerShell 在 SharePoint 中复制列表权限


曾经想要在 SharePoint 列表或库之间克隆权限吗?好吧,这是一个漂亮的 PowerShell 脚本,用于在 SharePoint 列表之间复制权限:


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

#PowerShell Function to copy permissions between Lists in SharePoint
Function Copy-ListPermissions()
{
 param(
     $WebURL,
     $SourceListName,
     $TargetListName
 )
 #Get the Web
 $Web = Get-SPweb $WebURL

 #Get Source and Target Lists
 $SourceList = $Web.lists[$SourceListName]
 $TargetList = $Web.lists[$TargetListName]

 #if permissions are Inherited in Source, apply it in Target list 
  if($SourceList.Permissions.Inherited)
   {
      $TargetList.ResetRoleInheritance()
   }
  else #Copy permissions from Source to Target List
  {
     #Reset the Inheritence in Target List
     $TargetList.BreakRoleInheritance($false)

     #Copy Source list permissions to Destination List
     $SourceList.RoleAssignments | foreach-object {
     $targetList.RoleAssignments.Add($_)
      }
  }
 $TargetList.Update()
}
#Call the function to copy list permissions 
Copy-ListPermissions "https://sharepoint.crescent.com/sites/operations/us" "Documents" "Invoice"

此脚本将所有用户和组从源列表复制到目标列表。已应用于目标列表的任何自定义权限都将丢失!上述方法可用于在 SharePoint 列表项和网站之间复制权限。

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

取消回复欢迎 发表评论:

关灯