Suppose i have a csv file as follows:
role member
role1 memberA
role1 memberB
role2 memberC
role3 memberX
role3 memberY
role3 memberC
I want to add to a database all members to the roles on the database
$csvR = (Import-Csv $csvFile).role
foreach ($Role in $csvR)
{
foreach ($Member in $Role)
{
& ".\AddMembers.ps1" -AddtoDatabaseOnOneServer "$Role" "$Member" "$DatabaseName" "$ServerInput"
}
}
Will this loop recognize for example to add memberA to role1, memberB to role1, memberC to role2, etc.? in other words, is this inner loop correct: foreach ($Member in $Role)

Import-Csvrepresent each row of the input CSV with aStringproperty for each column. It's not going to create any collections or do any further interpretation/association unless you instruct it to. Further, by setting$csvRto.roleyou're picking off theRoleproperty and discarding the rest of the object.Group-Objectcmdlet help. it can group the objects from yourImport-CSVby the.Roleproperty and then you can iterate thru the resulting groups to assign the.Memberto the.Role..Groupthat has all the matching objects from the CSV import in it. you can iterate thru that ... [grin] ///// if you replace that nasty, icky, useless picture of your sample data with several lines from your source, i could do a demo of the idea. i won't bother if you won't bother to post usable sample data, tho. [frown]$csvR = Import-Csv $csvFile; foreach ($row in $csvR) { $row.role; $row.member }. If your AddMembers.ps1 script only takes a single role and single member as a parameter, you will be doing some sort of iteration.