Hi everyone

I was just passed a list of about 100 groups that need to be created and then members put into said groups. The group creation portion was easy

    foreach ($group in $groups) {

    $groupProps = @{

      Name          = $group.name
      Path          = $group.path
      GroupScope    = $group.scope
      GroupCategory = $group.category
      Description   = $group.description

      }#end groupProps

    New-ADGroup @groupProps
    
}

I can’t figure out how to add the users to the group. The CSV has two columns name, members. When there is only one member to add to the group it works great. The problem is many of these groups have multiple people to be added, it throws an error that the identity can’t be found. This is what I have so far, what am i missing

$groups = Import-Csv ‘c:\scripts\group_members.csv‘

foreach ($group in $groups) {
    add-adgroupmember -identity $Group.name -members $Group.members
}

I know it is something stupid and small, but I am pounding my head against a wall

thanks

app

8 Spice ups

can you post the format of the csv? You probably have to parse the members into an array.

like so, but im sure you have to add more code to get the members in the right format.

foreach($group in $csv){
    $members = $group.members

    foreach($member in $members){
        Add-ADGroupMember $group.name -Members $member
    }
}
1 Spice up

this is what the CSV looks like

name,members
G_APP_my_darchda_prod_ro,"earlesb,houser"
G_APP_my_darch_prod_ro,"goodkinj"
G_APP_my_chives_prod_ro,"maddenc"

just split it by comma then?

foreach($group in $csv){
    $members = $group.members -split ","

    foreach($member in $members){
        Add-ADGroupMember $group.name -Members $member
    }
}
3 Spice ups

If you add the Server parameter, you could do also add the members right after you create the group as well.

1 Spice up