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, and 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 ID, you can use this trick to save time in copy-move SharePoint users:

  • Go to Site Actions >> Site Settings
  • Click on “People and Groups” under the Users and Permissions group
  • Pick required users from the source group. Click on “E-mail Users” from the “Actions” menu.
    Copy Users from One SharePoint Group to Another using PowerShell

  • This launches the default E-mail client such as Outlook. Now you can copy those IDs.
  • Head-on to the Target SharePoint group >> Add users and paste those copied IDs.

The above method could be relatively more straightforward when copying or moving a few users between SharePoint groups. Wouldn’t it be better to use the scripted way to copy multiple users in bulk?

PowerShell Script to Copy/Move Users from One SharePoint Group to Another :

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Input variables
$WebURL = "https://sharepoint.crescent.com/sites/Operations/"
$SourceGroupName="Operations Members"
$TargetGroupName="Operations Owners"

#Get the Web
$web = Get-SPWeb $WebURL

#Get the Source and Target Groups
$SourceGroup = $web.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $web.groups | where {$_.name -eq $TargetGroupName }

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

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? Let’s change the above script slightly to copy users from one SharePoint site group to another.

Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue

#Input variables
$SourceWebURL = "https://sharepoint.crescent.com/sites/Operations/"
$TargetWebURL = "https://sharepoint.crescent.com/sites/Marketing/"
$SourceGroupName="Operations Members"
$TargetGroupName="Marketing Members"

#Get the Webs
$SourceWeb = Get-SPWeb $SourceWebURL
$TargetWebURL= Get-SPWeb $TargetWebURL

#Get the Source and Target Groups
$SourceGroup = $SourceWeb.groups | where {$_.name -eq $SourceGroupName }
$TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

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

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

7 thoughts on “Copy Users from One SharePoint Group to Another using PowerShell

  • For anyone needing or wanting to use PnP instead, here’s a rewrite of the first script for copying users between groups. It’s a bit shorter since PnP has some tweaks. Salaudeen, thanks for always having a script for every single thing I need to do in SharePoint!

    $WebURL = “https://contoso.sharepoint.com/sites/Contoso”
    $SourceGroupName=”Contoso Members”
    $TargetGroupName=”Contoso Owners”

    Connect-PnPOnline -Url $WebURL -UseWebLogin

    $SourceGroup = Get-PnPGroupMembers -Identity $SourceGroupName

    foreach ($user in $SourceGroup)
    {
    Add-PnPUserToGroup -LoginName $user.LoginName -Identity $TargetGroupName
    Write-Host “Copied $($user.Title) from $SourceGroupName to $TargetGroupName”
    }

    Reply
  • Hello,
    If we want to move Sharepoint Groups users into sharepoint custom list which is having two columns 1) Email 2)access type.

    Reply
  • How can we do if Target is SharePoint Online URL??

    Reply
  • What if we need to go from multiple Sharepoint groups to a single Sharepoint group? Do we just do something like $SourceGroupName=”Operations Members” AND “Finance Members” ?

    Reply
    • Hi Clint,
      If you want to move from Multiple groups, the code goes like this:

      $SourceGroupNames=”Operations Members”, “Operations Owners”, “Operations Visitors”
      $TargetGroupName=”Operations Users”

      #Iterate through each source group
      foreach($GroupName in $SourceGroupNames)
      {
      #Get the Source and Target Groups
      $SourceGroup = $SourceWeb.groups | where {$_.name -eq $GroupName }
      $TargetGroup = $TargetWebURL.groups | where {$_.name -eq $TargetGroupName }

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

      Reply
  • For SharePoint 2013 I had to change to following and then it worked. Thanks

    $SourceGroup = $web.SiteGroups[$SourceGroupName]
    $TargetGroup = $web.SiteGroups[$TargetGroupName]

    Reply
  • Thank you – this was very helpful!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *