Author Posts

May 11, 2017 at 9:56 pm

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}

May 11, 2017 at 11:26 pm

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.