Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Copy Permissions from One SharePoint Site to Another using PowerShell

$
0
0
Requirement: Copy permissions from one site to another in SharePoint!

Solution: If you want to copy one SharePoint site to another site, there is no OOTB ways! However, You can use PowerShell to copy permissions between sites. Here is my PowerShell script to copy site permissions.

Copy Permissions from one site to another using PowerShell:
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://portal.crescent.com/ProjectHub/" -TargetWebURL "http://portal.crescent.com/TaxAudits/"

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>