Copy Permission Levels in SharePoint using PowerShell
Requirement: Copy permission level in SharePoint 2013 using PowerShell
PowerShell to Copy permission level programmatically in SharePoint
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 permission level, How about copying permission level between site collections?
Copy Permission Level between site collections using PowerShell:
PowerShell to Copy permission level programmatically in SharePoint
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 permission level, How about copying permission level between site collections?
Copy Permission Level between site collections using PowerShell:
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
No comments:
Please Login and comment to get your questions answered!