How is it possible to import 2 csv's and pipe each output to the other??

This topic contains 1 reply, has 2 voices, and was last updated by  Robert Carlson 5 months, 1 week ago.

  • Author
  • #70549


    Easy example :
    I have a list of users and I want all of them to be members of all of the security groups on the other ADGroups List
    $users = Import-CSV -Path $path
    $Groups = Import-CSV -Path $path

    Then Foreach($User in $Users) {Add-GroupMember -Identity "The Output from ADGroupList" -Members $User}

  • #70550

    Robert Carlson

    Assuming that you are using two different CSV files, one containing users and one containing groups, you can add all users to all groups (assuming you have the appropriate AD permissions) with the following:

    $Users = Import-Csv -Path ...Users.csv
    $Groups = Import-Csv -Path ...Groups.csv
    foreach ($group in $Groups) {
        foreach ($user in $Users) {
            Add-ADGroupMember -Identity $group -Members $user

    Another approach I believe would work would be to take all your user names from your users file and concatenate them into a comma-separated string, e.g. $userNames = "user1","user2",....... and then you could use the following instead:

    # Import users and groups and create string of of comma-seperated user names and store in $userNames
    foreach ($group in $Groups) {
        Add-ADGroupMember -Identity $group -Members $userNames

    If you are using one CSV with different columns for users and groups, I would need more information about the CSV file layout and then some small modifications would need to be made.

You must be logged in to reply to this topic.