I am trying to make a script to add users to the AD groups based on header, the CSV looks like this:
Group1 Group2 Group3 UserA UserC UserA UserB UserC
The closest script I find is below, but this based below format, which is little different..
Group Accountname group1 user1 group1 user2 group1 user3
Import-Module ActiveDirectory
$list = Import-Csv ".\Bulk_Import.csv"
foreach ($user in $list) {
Add-ADGroupMember -Identity $user.Group -Member (Get-ADUser $user.Accountname)
}
Is that possible for script to add users based on my format, and ignore error if user is already in the group?