Sharepoint group copy users


In Sharepoint sometimes users have difficulties to grasp the permissions system.

You may have to change users membership quite a few times because ‘user X must have the same rights as User Y’.

If you have more thtan a couple of users, it can become quickly very boring.

The following snippet from the ‘lazy admin’ collection just does that: take a sharepoint group copy users to another group.

<pre class="lang:ps decode:true " title="Sharepoint group copy users to another group"># Add-PSSnapin Microsoft.SharePoint.PowerShell 
Copy sharepoint users between groups
Copy users in a Sharepoint group to another Sharepoint Group
  WebURL: site URL
  SourceGroupName: name of the source group
  TargetGroupName: name of the target group
Copy-SPGroupToGroup -WebURL "https://foobar/" -SourceGroupName "VIPs" -TargetGroupName "Project Managers"
 use Sitegroups in case group has not been granted permissions on the site

Function Copy-SPGroupToGroup {

$web = Get-SPWeb $WebURL

if ($web -eq $null) {
  throw "$WebURL does not match a site or site collection"

#Get the Source and Target Groups

$SourceGroup = $web.Sitegroups | where {$ -eq $SourceGroupName }
$TargetGroup = $web.Sitegroups | where {$ -eq $TargetGroupName }

if ($SourceGroup -eq $null) {
    throw "SourceGroup $SourceGroupName not found"

if ($TargetGroup -eq $null) {
    throw "Target Group $TargetGroupName not found"

#Iterate through each users in the source group

    foreach ($user in $SourceGroup.users)

        Write-Verbose "Copied $user from $SourceGroup to $TargetGroup"
        #To move users, Just remove