Copy Permissions from One SharePoint Site to Another using PowerShell

Requirement: Copy permissions from one site to another in SharePoint!

Solution:

If you want to copy one SharePoint site to another site, there are no OOTB ways! However, You can use PowerShell to copy permissions between sites. Here is my PowerShell script to copy site permissions:

copy permissions from one sharepoint site to another using powershell

Copy Permissions from one site to another using PowerShell:

Are you the site owner for one or more SharePoint sites and need to copy the permissions from one site to another? If so, PowerShell can help! In this post, we will walk through how to use PowerShell to copy permissions from one SharePoint site to another.

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/" 

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

11 thoughts on “Copy Permissions from One SharePoint Site to Another using PowerShell

  • I got the same error too. Any one know how to handle that??

    Reply
  • I got the following error: The term ‘Get-SPWeb’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

    Reply
    • This script is written for SharePoint On-premises and must be executed from any of the SharePoint server in the farm.

      Reply
  • Hi,

    Is there any script available for SharePoint Online to perform this activity.

    Reply
  • Hi Does this also copy the SharePoint Groups from the source or it just copies users and their permissions?

    E.g Managers …. Full Control or Name.Surname … Full Control?

    Reply
    • This script copies all users and groups – that has permissions to source web to the target!

      Reply
  • Hi, does this also work if lists have broken inheritance and custom permissions?

    Reply
  • You check Inherit permission Source Web. If Inherit then you stop inheriting permission. Hope help you!

    Reply
  • Hi,

    I am getting the following error on using the above code: Exception calling “Add” with “1” argument(s): “0x80070003”. please let me know, how to fix this?

    Reply
    • I too getting the same issue

      Hi,

      I am getting the following error on using the above code: Exception calling “Add” with “1” argument(s): “0x80070003”. please let me know, how to fix this?

      #Read more: https://www.sharepointdiary.com/2016/10/copy-site-permissions-in-sharepoint-using-powershell.html#ixzz80CCzFPy8

      Reply

Leave a Reply

Your email address will not be published. Required fields are marked *