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

[玩转系统] 使用 PowerShell 将权限从一个 SharePoint 站点复制到另一个 SharePoint 站点

作者:精品下载站 日期:2024-12-14 21:02:28 浏览:14 分类:玩电脑

使用 PowerShell 将权限从一个 SharePoint 站点复制到另一个 SharePoint 站点


要求: 将权限从 SharePoint 中的一个网站复制到另一个网站!

解决方案:

如果您想将一个 SharePoint 网站复制到另一个网站,没有任何 OOTB 方法!但是,您可以使用 PowerShell 在站点之间复制权限。这是我用于复制站点权限的 PowerShell 脚本:

[玩转系统] 使用 PowerShell 将权限从一个 SharePoint 站点复制到另一个 SharePoint 站点

使用 PowerShell 将权限从一个站点复制到另一个站点:

您是一个或多个 SharePoint 网站的网站所有者,并且需要将权限从一个网站复制到另一个网站吗?如果是这样,PowerShell 可以提供帮助!在这篇文章中,我们将演练如何使用 PowerShell 将权限从一个 SharePoint 网站复制到另一个。


Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
 
#PowerShell Function to copy permissions from one site to another
Function Copy-SitePermissions()
{
 param(
     $SourceWebURL,
     $TargetWebURL
 )
 Try {
  #Set the Error Action
    $ErrorActionPreference = "Stop"
  
  #Get the Source and Target Webs
  $SourceWeb = Get-SPWeb $SourceWebURL
  $TargetWeb = Get-SPWeb $TargetWebURL
  
  #if permissions are Inherited in the target, Break it!
  if($TargetWeb.Permissions.Inherited)
  {
   #Reset the Inheritence in Target Web
   $TargetWeb.BreakRoleInheritance($false)
  }
   #Copy permissions from Source to Target Web
     $SourceWeb.RoleAssignments | foreach-object {
     $TargetWeb.RoleAssignments.Add($_)
     }
    $TargetWeb.Update()
    Write-Host "Permissions copied from Source Site to the Target!" -f Green
 }
 catch {
   Write-Host $_.Exception.Message -ForegroundColor Red
 }
 finally {
  #Reset the Error Action to Default
  $ErrorActionPreference = "Continue"
 }
}

#Call the function to copy Web permissions 
Copy-SitePermissions -SourceWebURL "https://portal.crescent.com/ProjectHub/" -TargetWebURL "https://portal.crescent.com/TaxAudits/" 

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

取消回复欢迎 发表评论:

关灯