【发布时间】:2018-10-03 20:11:36
【问题描述】:
所以我一直在尝试将所有当前 AD 用户添加到特定的通讯组。
我将文件导入为 CSV 或 TXT,但我不断收到关于无法转换参数的错误:
到目前为止,我的代码已经转换,但我的第一次尝试是
$update = gc 'File\path.txt'
ForEach ($ADuser in $update) {
Add-DistributionGroupMember -Identity All -member $update
}
我的第二次尝试是
import-csv 'C:\Users\andrew.schilling\Desktop\testing.csv'
$update = import-csv 'File\path\of\csv.csv' | select ObjectGUID
ForEach ($SamAccountName in $update) {
$newmember = $update.ObjectGUID
$newmember | foreach {
Add-DistributionGroupMember -Identity All -Member $newmember
}}
我仍然得到同样的错误:
无法处理参数“成员”的参数转换。不能 转换类型的“System.Collections.ArrayList”值 “System.Collections.ArrayList”键入 "Microsoft.Exchange.Configuration.Tasks.RecipientWithAdUserGroupIdParameter`1[Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter]"。
如有任何建议,请告诉我!
【问题讨论】:
-
看起来您正在将文件的内容添加到
$update变量中,然后在循环中,您使用$update变量作为-member参数。您可能需要将其更改为$ADuser。 -
这似乎做到了。感谢您的帮助
标签: powershell csv exchange-server