SharePoint Online: Copy/Move Users from One Group to Another

Requirement: Move users from one group to another in SharePoint Online

How to Copy or Move Users Between SharePoint Online Groups?

Do you need to copy users from one group to another in SharePoint Online? Maybe you’ve just set up a new group and need to populate it with users from an existing group. Perhaps you want to move a user from one group to another. Whatever the reason, there are a few ways you can do this. This article will show you how to copy users from one group to another using PowerShell and show you how to do it manually in SharePoint Online. Let’s get started!

Well, there is no direct way to copy or move users between SharePoint Online groups. But you can achieve it by following the below steps:

  • Click on Settings gear >> Site Settings
  • Click on “People and Groups” under the “Users and Permissions” group
  • Select the Source group name from the left navigation >> Select All Users by ticking the checkbox in the header >> Click on “E-mail Users” from the “Actions” menu. This opens the default email client with all users of the group. Copy them! 
    sharepoint online move users from one group to another
  • Navigate to the destination group in SharePoint Online site>> Click on “Add users and paste those copied emails. You can remove them from the source group in case its “Move”.

The above method could be relatively simpler when you have to copy or move a few users between SharePoint groups. Wouldn’t it be better to use the scripted way to copy multiple users in bulk?

SharePoint Online: Move Users from One Group to Another using PowerShell

Here is how you can move users from one group to another in SharePoint Online:

#Config Variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$SourceGroupName = "Marketing Team"
$DestinationGroupName = "Marketing Managers"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get Members of the Source Group
$SourceGroup = Get-PnPGroup -Identity $SourceGroupName | Select-Object Users

#Add users to destination group
Foreach ($User in $SourceGroup.Users)
{
    #Frame User ID
    $UserID = "i:0#.f|membership|"+$User.Email
    #Add user to Group
    Add-PnPGroupMember -LoginName $UserID -Identity $DestinationGroupName

    #Remove user from source group
    Remove-PnPGroupMember -LoginName $UserID -Identity $SourceGroupName

    Write-host "User Moved :"$User.Email
}

You can comment out the “Remove-PnPGroupMember” (Line#20) to perform copy users between groups.

PowerShell to Move Users between Groups from One Site to Another

How about moving users between groups in different sites?

#Parameters
$SourceSiteURL = "https://crescent.sharepoint.com/sites/marketing"
$DestinationSiteURL = "https://crescent.sharepoint.com/sites/Purchase"
$SourceGroupName = "Marketing Members"
$DestinationGroupName = "Purchase Members"

Try {
    #Connect to the Source and Destination Sites
    $SourceSite = Connect-PnPOnline -Url $SourceSiteURL -Interactive -ReturnConnection
    $DestinationSite = Connect-PnPOnline -Url $DestinationSiteURL -Interactive -ReturnConnection

    #Get Members of the Source Group
    $SourceGroup = Get-PnPGroup -Connection $SourceSite -Identity $SourceGroupName | Select-Object Users
 
    #Add users to destination group
    Foreach ($User in $SourceGroup.Users)
    {
        #Resolve the User
        $ResolvedUser = Get-PnPUser -Connection $DestinationSite | Where-Object LoginName -eq $User.LoginName
        If($ResolvedUser -eq $null) {        
            $ResolvedUser = New-PnPUser -LoginName $User.LoginName -Connection $DestinationSite
        }

        #Add user to Group
        Add-PnPGroupMember -Connection $DestinationSite -LoginName $User.LoginName -Identity $DestinationGroupName
 
        #Remove user from source group
        Remove-PnPGroupMember -Connection $SourceSite -LoginName $User.LoginName  -Identity $SourceGroupName
 
        Write-host "User Moved :"$User.LoginName
    }
}
Catch {
    write-host -f Red "`tError:" $_.Exception.Message
}

Please note, If you have external users enabled for the source site, You must do so on the destination site as well (which is obvious, isn’t it?).

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

3 thoughts on “SharePoint Online: Copy/Move Users from One Group to Another

  • Could you explain how to to do this between two different sites?

    Reply
  • Thx!!! You ‘re saved my day 🙂

    Reply

Leave a Reply