Ever wanted to clone permissions between SharePoint lists or Libraries? Well, Here is the nifty PowerShell script to copy permissions between SharePoint lists:
The above method can be used to copy permissions between SharePoint list items and sites.
Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinueThis script copies all users and groups from the source list to target list. Any custom permissions already applied on the target list will be lost!
#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 "http://sharepoint.crescent.com/sites/operations/us" "Documents" "Invoice"
The above method can be used to copy permissions between SharePoint list items and sites.