Copy Permission Levels in SharePoint using PowerShell

Requirement: Copy permission level in SharePoint 2013 using PowerShell

copy permission level in sharepoint using powershell

PowerShell to Copy permission level programmatically in SharePoint

Have you ever needed to copy a permission level in SharePoint? Maybe you need to create a new permission level that is similar to an existing one, but with some changes. Or maybe you need to duplicate a permission level for testing purposes. In any case, this blog post will show you how to use PowerShell to copy SharePoint permission levels.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

#Configuration parameters
$WebURL="https://portal.crescent.com"
$SourcePermissionLevelName="Contribute"
$TargetPermissionLevelName="Contribute without Delete"

#Get the Source Permission Level
$SourcePermissionLevel = $Web.RoleDefinitions[$SourcePermissionLevelName]
#sharepoint copy permission level
$TargetPermissionLevel = New-Object Microsoft.SharePoint.SPRoleDefinition($SourcePermissionLevel)

#Remove "Delete" Base permission 
$TargetPermissionLevel.BasePermissions = "ViewListItems, AddListItems, EditListItems, OpenItems, ViewVersions, DeleteVersions, ManagePersonalViews, ViewFormPages, Open, ViewPages, CreateSSCSite, BrowseDirectories, BrowseUserInfo, AddDelPrivateWebParts, UpdatePersonalWebParts, UseClientIntegration, UseRemoteAPIs, CreateAlerts, EditMyUserInfo"

#Add the New Permission Level
$TargetPermissionLevel.Name= $TargetPermissionLevelName
#permission level description
$TargetPermissionLevel.Description="Contribute without Delete Permission Level"
$web.RoleDefinitions.Add($TargetPermissionLevel)
write-host "Permission level Copied successfully!"

The above PowerShell script copies permission level programmatically in SharePoint 2013/2010 and applies given base permissions. While it copies an existing permission level into a new one, How about copying the permission level between site collections?

Copy Permission Level between site collections using PowerShell:

When it comes to copying permission levels between SharePoint sites, you can’t achieve with the web browser user interface. However, you can use PowerShell to copy permission levels between SharePoint sites.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue 

Function Copy-PermissionLevel($SourceWebURL, $TargetWebURL, $PermissionLevelName)
{
 #Get the Webs
 $SourceWeb = Get-SPWeb $SourceWebURL
 $TargetWeb = Get-SPWeb $TargetWebURL
 
 #Check if given Source permission level exists
 if($SourceWeb.RoleDefinitions[$PermissionLevelName] -ne $null)
 {
  #Get the Source Permission Level
  $SourcePermissionLevel = $SourceWeb.RoleDefinitions[$PermissionLevelName]
  
  #Check if Target permission level name already exists!
  if($TargetWeb.RoleDefinitions[$PermissionLevelName] -eq $null)
  {
   #sharepoint copy permission level
   $TargetPermissionLevel = New-Object Microsoft.SharePoint.SPRoleDefinition($SourcePermissionLevel)
   #Add the New Permission Level
   $TargetWeb.RoleDefinitions.Add($TargetPermissionLevel)

   write-host "Permission level Copied successfully!" -f Green
  }
  else
  {
   write-host "Permission Level Already Exists!" -f Red
  }
 }
 else
 {
  write-host "Source Permission Level Not Found!" -f Red
 }
}

#Configuration Variables
$SourceURL="https://portal.crescent.com/"
$TargetURL="https://portal.crescent.com/sites/sales"
$PermissionLevelName="Contribute without Deletes"

#Call the function to copy permission level between site collections
Copy-PermissionLevel $SourceURL $TargetURL $PermissionLevelName 

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

Leave a Reply

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