多个用户添加到多个组从一个导入CSV(跟踪查询) [英] Add multiple users to multiple groups from one import csv (follow up query)

查看:263
本文介绍了多个用户添加到多个组从一个导入CSV(跟踪查询)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种方式来填充多个通讯组,多个用户名。我碰到<一href="http://stackoverflow.com/questions/16651580/add-multiple-users-to-multiple-groups-from-one-import-csv#new-answer?newreg=49d4e98054ae4ec7aa6761c0aa7d354e">a本网站上所写的成员弗罗德F. 脚本:

I was looking for a way to populate multiple distribution groups with multiple user names. I came across a script on this site written by member Frode F.:

Import-Csv "C:\Scripts\Import Bulk Users into bulk groups\bulkgroups3.csv" | Group-Object Group | % {
    #Foreach Group, get ADUser object for users and add members
    $users = $_.Group | % { Get-ADUser $_.Accountname }
    Add-ADGroupMember -Identity $_.Name -Member $users
}

这是工作时的CSV文件包含在列1 2个不同的组和多个用户在第2栏10行。 当的csv包含几百行,仍然只有2组未能填充组在所有。这些都是错误:

This was working when the csv file contained about 10 lines with 2 different groups in column 1 and multiple users in column 2. When the csv contains a few hundred lines, still only 2 groups it fails to populate the groups at all. These are the errors:

Add-ADGroupMember : The specified account name is already a member of the group
At C:\scripts\AddUsersDistributionGroups.ps1:6 char:22
+     Add-ADGroupMember <<<<  -Identity $_.Name -Member $users
    + CategoryInfo          : NotSpecified: (Group A:ADGroup) [Add-ADGroupMember], ADException
    + FullyQualifiedErrorId : The specified account name is already a member of the group,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

Add-ADGroupMember : The specified account name is already a member of the group
At C:\scripts\AddUsersDistributionGroups.ps1:6 char:22
+     Add-ADGroupMember <<<<  -Identity $_.Name -Member $users
    + CategoryInfo          : NotSpecified: (Group B:ADGroup) [Add-ADGroupMember], ADException
    + FullyQualifiedErrorId : The specified account name is already a member of the group,Microsoft.ActiveDirectory.Management.Commands.AddADGroupMember

谁能帮助?

推荐答案

也许有一个限制,许多成员如何添加-ADGroupMember 可以处理一次,并croaks如果你通过在 - 成员参数数以百计的集合?相反,所有的用户分组到一个集合中,尝试将他们一次一个:

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
}

这假定在组的值帐户名列的有效身份证性能 - 他们不得不是为了让你报工作的脚本。但是请注意,这个脚本会需要很长的时间来运行,因为AD cmdlet的通常运行慢,你会被执行添加-ADGroupMember 一次,每个用户(即每行的CSV文件),而不是一次每个组。你可能会发现它有用添加一行到的foreach对象块指示,让你知道它的工作,而不是被卡住的进步。

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.

这篇关于多个用户添加到多个组从一个导入CSV(跟踪查询)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆