Create AD Group and Copy a Group’s Members with PowerShell

This week, I was asked if I could export a list of users who were members of a specific group in Active Directory. What's this list for? We're working on a project that requires us to create a new security group in Active Directory and we're going to add all the users on the list to the new group. I determined that this new group really was necessary. I can do even better than providing you with a list. I can create the new AD group, output a list of users, and import them into the new group.

I had previously created a couple of PowerShell scripts that would help me get started. One of them created an AD group and the other added a single user to an AD group. I combined my existing scripts.

 1$newGrpName = 'NewADGroup'
 2$grpScope = 'Global'
 3$description = 'New AD Group'
 4$grpCat = 'Security'
 5$path = 'OU=security,OU=groups,OU=test,DC=mikefrobbins,DC=com'
 6$existingGrpName = 'ExistingADGroup'
 8New-ADGroup -Name $newGrpName -GroupScope $grpScope -Description $description -GroupCategory $grpCat -Path $path -PassThru  |
 9Add-ADGroupMember -Members (Get-ADGroupMember -Identity $existingGrpName) -PassThru |
10Get-ADGroupMember |
11Select-Object -Property Name