Add List of AD Groups to Multiple User Accounts
#Make multiple user accounts members of a list of AD groups, based on information in a CSV file
$csvPath = "C:\Users\Public\Documents\User_AD_Group.csv"
$usersAndGroups = Import-Csv -Path $csvPath
$users = $usersAndGroups | Select-Object -ExpandProperty UserName -Unique
$groups = $usersAndGroups | Select-Object -ExpandProperty GroupName -Unique
foreach ($user in $users) {
foreach ($group in $groups) {
Add-ADGroupMember -Identity $group -Members $user
}
}
Write-Host "Each user has been added to all listed groups"