【问题标题】:Trying to add all current AD users to a Distribution Group尝试将所有当前 AD 用户添加到通讯组
【发布时间】: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


【解决方案1】:

我将此添加为答案,以便其他人可以看到原因和解决方案。

看起来您正在将文件的内容添加到$update 变量中,然后在循环中,您使用$update 变量作为-member 参数的值。这需要改为$ADuser

$update = gc 'File\path.txt' 
ForEach ($ADuser in $update) { 
    Add-DistributionGroupMember -Identity All -member $ADuser  
}

【讨论】:

  • 对不起,我是这个网站的新手
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-12-30
  • 1970-01-01
  • 2021-10-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多