If User is Member of Group A, Remove Group A, then add to Group B

Jon Hatfield 46 Reputation points

Title says it all. I'm trying to create a PowerShell script that will do the following:

Search for all members of Group A

Remove from Group A

Add to Group B

Any tips are appreciated!

Active Directory
Active Directory
A set of directory-based technologies included in Windows Server.
5,984 questions
Windows Server PowerShell
Windows Server PowerShell
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.PowerShell: A family of Microsoft task automation and configuration management frameworks consisting of a command-line shell and associated scripting language.
5,404 questions
0 comments No comments
{count} votes

Accepted answer
  1. Andreas Baumgarten 98,621 Reputation points MVP

    The script should look like this (not tested!)

    Import-Module ActiveDirectory  
    Get-ADGroupMember -Identity "GroupA" |  
            ForEach-Object {Add-AzADGroupMember -Identity "GroupB" -Members $_  
                            Remove-ADGroupMember "GroupA" $_ -Confirm:$false  



    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Andreas Baumgarten

    1 person found this answer helpful.
    0 comments No comments

1 additional answer

Sort by: Most helpful
  1. Jon Hatfield 46 Reputation points

    That worked perfectly. Thank you!

    0 comments No comments