Powershell 正在尝试将所有当前广告用户添加到通讯组
所以我一直在尝试将所有当前的广告用户添加到一个特定的分发组中 我将文件导入为CSV或TXT,但我不断收到一个错误,即无法转换参数: 到目前为止,我的代码已经转换,但我的第一次尝试是Powershell 正在尝试将所有当前广告用户添加到通讯组,powershell,csv,exchange-server,Powershell,Csv,Exchange Server,所以我一直在尝试将所有当前的广告用户添加到一个特定的分发组中 我将文件导入为CSV或TXT,但我不断收到一个错误,即无法转换参数: 到目前为止,我的代码已经转换,但我的第一次尝试是 $update = gc 'File\path.txt' ForEach ($ADuser in $update) { Add-DistributionGroupMember -Identity All -member $update } import-csv 'C:\Users\andrew.sch
$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
}}
我的第二次尝试是
$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
}}
我仍然得到相同的错误:
无法处理参数“Member”上的参数转换。不能
转换类型的“System.Collections.ArrayList”值
“System.Collections.ArrayList”以键入
“Microsoft.Exchange.Configuration.Tasks.RecipientWithAdUserGroupIdParameter`1[Microsoft.Exchange.Configuration.Tasks.RecipientIdParameter]”
请让我知道任何建议 我将此添加为一个答案,以便其他人可以看到原因和解决方案
看起来您正在将文件内容添加到
$update
变量中,然后在循环中,使用$update
变量作为-member
参数的值。这需要更改为$ADuser
$update = gc 'File\path.txt'
ForEach ($ADuser in $update) {
Add-DistributionGroupMember -Identity All -member $ADuser
}
看起来您正在将文件内容添加到
$update
变量中,然后在循环中,使用$update
变量作为-member
参数。您可能需要将其更改为$ADuser
。这似乎可以做到。谢谢你的帮助很抱歉我是新来的