Thursday, April 17, 2014

Copy Users from One SharePoint Group to Another using PowerShell

Recently, I had a requirement to copy users from one SharePoint group to another group. Unfortunately, SharePoint doesn't support nested groups. Simply renaming the group didn't help us! Well, There is no direct way to copy users from one group to another, but without having to retype each user IDs, you can use this trick to save time in copy-move SharePoint users:

Copy users from one SharePoint site collection to another using PowerShell:
The above script copies users between SharePoint groups of the same site. Can we copy users between groups in different site collections? Why not? Lets change the above script slightly to copy users from one SharePoint site group to another.

#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) }}