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.

$newGrpName = 'NewADGroup'
$grpScope = 'Global'
$description = 'New AD Group'
$grpCat = 'Security'
$path = 'OU=security,OU=groups,OU=test,DC=mikefrobbins,DC=com'
$existingGrpName = 'ExistingADGroup'

New-ADGroup -Name $newGrpName -GroupScope $grpScope -Description $description -GroupCategory $grpCat -Path $path -PassThru  |
Add-ADGroupMember -Members (Get-ADGroupMember -Identity $existingGrpName) -PassThru |
Get-ADGroupMember |
Select-Object -Property Name

µ