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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# Add-PSSnapin Microsoft.SharePoint.PowerShell <# .SYNOPSIS Copy sharepoint users between groups .DESCRIPTION Copy users in a Sharepoint group to another Sharepoint Group .INPUTS WebURL: site URL SourceGroupName: name of the source group TargetGroupName: name of the target group .OUTPUTS None .EXAMPLE Copy-SPGroupToGroup -WebURL "https://foobar/" -SourceGroupName "VIPs" -TargetGroupName "Project Managers" .NOTES use Sitegroups in case group has not been granted permissions on the site #> Function Copy-SPGroupToGroup { param( [Parameter(Mandatory=$true,Position=2)] [string]$WebURL, [Parameter(Mandatory=$true,Position=0)] [string]$SourceGroupName, [Parameter(Mandatory=$true,Position=1)] [string]$TargetGroupName ) $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 {$_.name -eq $SourceGroupName } $TargetGroup = $web.Sitegroups | where {$_.name -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) { $TargetGroup.AddUser($user) Write-Verbose "Copied $user from $SourceGroup to $TargetGroup" #To move users, Just remove #$SourceGroup.RemoveUser($user) } } |