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

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s