Copy Group Permissions

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
 
#Input variables
$SourceWebURL = "https://abc.def.com/sites/test/"
$TargetWebURL = "https://def.hij.com/sites/Test2"
$SourceGroupName="T7D Owners"
$TargetGroupName="E7R Owners"
 
#Get the Webs
$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL
 
#Get the Source and Target Groups
$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }
 
#Iterate through each users in the source group
foreach ($user in $SourceGroup.users)
{
   $TargetGroup.AddUser($user)
    Write-Host "Copied $user from $SourceGroup to $TargetGroup"
    #To move users, Just remove them from source group
    #$SourceGroup.RemoveUser($user)
}
$SourceWeb.Dispose();
$TargetWebURL.Dispose();


Comments

Popular posts from this blog

How to Improve Workflow Performance in SharePoint Server 2010

PowerShell Script to Check and Generate Report on Access Rights for a Specific User:

Disable Loopbackcheck using PowerShell