$groups = Import-Csv ‘c:\\scripts\\group_members.csv‘\n\nforeach ($group in $groups) {\n add-adgroupmember -identity $Group.name -members $Group.members\n}\n\n<\/code><\/pre>\nI know it is something stupid and small, but I am pounding my head against a wall<\/p>\n
thanks<\/p>\n
app<\/p>","upvoteCount":8,"answerCount":5,"datePublished":"2023-04-18T16:14:11.000Z","author":{"@type":"Person","name":"apperrault","url":"https://community.spiceworks.com/u/apperrault"},"suggestedAnswer":[{"@type":"Answer","text":"
Hi everyone<\/p>\n
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<\/p>\n
foreach ($group in $groups) {\n\n $groupProps = @{\n\n Name = $group.name\n Path = $group.path\n GroupScope = $group.scope\n GroupCategory = $group.category\n Description = $group.description\n\n }#end groupProps\n\n New-ADGroup @groupProps\n \n}\n<\/code><\/pre>\nI 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<\/p>\n
$groups = Import-Csv ‘c:\\scripts\\group_members.csv‘\n\nforeach ($group in $groups) {\n add-adgroupmember -identity $Group.name -members $Group.members\n}\n\n<\/code><\/pre>\nI know it is something stupid and small, but I am pounding my head against a wall<\/p>\n
thanks<\/p>\n
app<\/p>","upvoteCount":8,"datePublished":"2023-04-18T16:14:11.000Z","url":"https://community.spiceworks.com/t/group-membership-csv-and-powershell/950320/1","author":{"@type":"Person","name":"apperrault","url":"https://community.spiceworks.com/u/apperrault"}},{"@type":"Answer","text":"\n\n
<\/div>\n
Apperrault:<\/div>\n
\nI can’t figure out how to add the users to the group. The CSV has two columns name, members.<\/p>\n<\/blockquote>\n<\/aside>\n
can you post the format of the csv? You probably have to parse the members into an array.<\/p>\n
like so, but im sure you have to add more code to get the members in the right format.<\/p>\n
foreach($group in $csv){\n $members = $group.members\n\n foreach($member in $members){\n Add-ADGroupMember $group.name -Members $member\n }\n}\n<\/code><\/pre>","upvoteCount":1,"datePublished":"2023-04-18T16:22:44.000Z","url":"https://community.spiceworks.com/t/group-membership-csv-and-powershell/950320/2","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"this is what the CSV looks like<\/p>\n
name,members\nG_APP_my_darchda_prod_ro,\"earlesb,houser\"\nG_APP_my_darch_prod_ro,\"goodkinj\"\nG_APP_my_chives_prod_ro,\"maddenc\"\n\n<\/code><\/pre>","upvoteCount":0,"datePublished":"2023-04-18T17:07:12.000Z","url":"https://community.spiceworks.com/t/group-membership-csv-and-powershell/950320/3","author":{"@type":"Person","name":"apperrault","url":"https://community.spiceworks.com/u/apperrault"}},{"@type":"Answer","text":"just split it by comma then?<\/p>\n
foreach($group in $csv){\n $members = $group.members -split \",\"\n\n foreach($member in $members){\n Add-ADGroupMember $group.name -Members $member\n }\n}\n<\/code><\/pre>","upvoteCount":3,"datePublished":"2023-04-18T17:08:13.000Z","url":"https://community.spiceworks.com/t/group-membership-csv-and-powershell/950320/4","author":{"@type":"Person","name":"Neally","url":"https://community.spiceworks.com/u/Neally"}},{"@type":"Answer","text":"If you add the Server parameter, you could do also add the members right after you create the group as well.<\/p>","upvoteCount":1,"datePublished":"2023-04-18T17:49:45.000Z","url":"https://community.spiceworks.com/t/group-membership-csv-and-powershell/950320/5","author":{"@type":"Person","name":"saidbrandon","url":"https://community.spiceworks.com/u/saidbrandon"}}]}}
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
Neally
(Neally)
April 18, 2023, 4:22pm
2
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"
Neally
(Neally)
April 18, 2023, 5:08pm
4
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