Sharepoint Copy List Permission using Sharepoint Powershell

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue

 

#PowerShell Function to copy permissions between Lists in SharePoint

Function Copy-ListPermissions()

{

param(

$WebURL,

$TargetWwebURL,

$SourceListName,

$TargetListName

)

#Get the Web

$Web = Get-SPweb $WebURL

$TargetWeb=Get-SPweb $TargetWebURL

#Get Source and Target Lists

$SourceList = $Web.lists[$SourceListName]

$TargetList = $TargetWeb.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 “Source Site url” “Dest Site Url” “Source List” “Dest List”

Leave a Reply

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