Add multiple users to multiple groups from one import csv (follow up query)

本小妞迷上赌 提交于 2019-12-02 06:04:52

Perhaps there's a limit to how many members Add-ADGroupMember can handle at once, and it croaks if you pass the -Members parameter a collection of hundreds? Instead of grouping all the users into a collection, try adding them one at a time:

Import-Csv "C:\Scripts\Import Bulk Users into bulk groups\bulkgroups3.csv" | %{
    Add-ADGroupMember -Identity $_.Group -Members $_.Accountname
}

This assumes that the values in the Group and Accountname columns are valid identity properties--which they'd have to be in order for the script you quoted to work. Note, though, that this script will take a long time to run, because the AD cmdlets usually execute slowly, and you'll be executing Add-ADGroupMember once per user (i.e., per line in the CSV file) rather than once per group. You might find it useful to add a line to the Foreach-Object block indicating progress so that you know it's working rather than getting stuck.

I ran into the same problem with adding multiple members via the Add-ADGroupMember and I think I found the solution. Thought I'd share it for posterity.

It has nothing to do with limitations on the number of members that can be handled....the cmdlet can handle thousands.

The issue is that the list of members passed via the -MEMBERS argument cannot have duplicates. If there are duplicates in that list then we get the error above.

The resolution? Either pass clean data without dupes or use the foreach argument to pass one member at a time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!