Creating AD Group - How to pass this through?

Welcome Forums General PowerShell Q&A Creating AD Group - How to pass this through?

This topic contains 1 reply, has 2 voices, and was last updated by

1 month, 3 weeks ago.

  • Author
  • #167974

    Topics: 1
    Replies: 0
    Points: -8
    Rank: Member

    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 $ -DisplayName $ -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

  • #167998

    Topics: 6
    Replies: 12
    Points: 50
    Rank: Member

    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"}

You must be logged in to reply to this topic.