Creating AD Group - How to pass this through?

Hi everyone,

So I’m a little bit new to PowerShell and I’m trying to create a loop to create Distribution Groups within my AD while first creating the set inputs.

Here is my code so far:

Import-Module ActiveDirectory
Set-Location AD:

$prefix = “Prefix-”

$name = “Test-Name-1, Test-Name-2, Test-Name-3, Test-Name-4”

#Append prefix to name

$distGroupName = $name.Split(’,’) | ForEach-Object {



Foreach ($name in $distGroupName) {New-ADGroup -Name $.name -DisplayName $.name) -GroupCategory Distribution -GroupScope Global -Path “OU=Distribution,OU=EXAMPLE,DC=GLOBAL,DC=COM”}


When I’m trying this I’m getting: Cannot validate argument on parameter ‘Name’. the argument is null or empty. Provide an argument that is not null or empty, and then try the command again.

I’m trying to pass off the joined $prefix and $name in the array $distGroupName to New-ADGroup. How would I go about doing this?


Thank you,

David Thao

Hi David!




#I suggest checking the results of your variables!

$distGroupName = $name.Split(',') | ForEach-Object {



write-verbose "$distGroupName" -verbose

Foreach ($name in $distGroupName) {
write-verbose "$name" -verbose
New-ADGroup -Name $ -DisplayName $ -GroupCategory Distribution -GroupScope Global -Path "OU=Distribution,OU=EXAMPLE,DC=GLOBAL,DC=COM"}