Copy Users to another Site Collection

Hey Folks,

Please find below script to copy users from one site collection to another in SharePoint User Group.


Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

$SourceWebURL = "YourSourceSiteUrl"
$TargetWebURL = "YourTargetedSiteUrl"
$SourceGroupName="YourSourceGroupName"
$TargetGroupName="YourTargetGroupName"

$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL

$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

foreach ($user in $SourceGroup.users)
{
$TargetGroup.AddUser($user)
Write-Host "Copied $user from $SourceGroup to $TargetGroup"
}

Happy SharePointing 🙂

Advertisements