none
Error in Copying data from one site collection to another - Powershell

    Question

  • Hi,

    I have an InfoPath form library, which I am trying to move the forms from one site collection to another, including the permissions.

    I am able to copy the infopath forms from one site to another site using powershell without any issues but on copying permissions from one site to another, I am getting the below error:

    Exception calling "Add" with "1" argument(s): "<nativehr>0x80070003</nativehr><nativestack></nativestack>"

    Below is the code Powershell Script to copy permissions from one site to another site:

    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 http://source-sharepoint-url/  -TargetWebURL http://destination-sharepoint-url/

    How to copy the item level permission for each of the forms to the target site collection?

    Thanks

    Monday, March 13, 2017 10:18 AM

All replies