在 powershell 中批量添加 managedby
bulk add managedby in powershell
我在为通讯组添加多个由用户管理时遇到问题。该命令运行良好,但是当我去检查发行版组中的用户管理时,唯一添加的人是 csv 文件列表中的最后一个人。我使用了同一个文件来添加成员,所以我不确定为什么它不起作用。
这就是我 运行
import-csv "path to file" | foreach {set-distributiongroup -identity "group name" -Managedby $_.name}
我做错了什么吗? Google 今晚不是我的朋友。
您每次都在覆盖现有值。循环中的最后一个用户将成为管理员。
Import-Csv "path to file" | ForEach-Object {
set-distributiongroup -identity "group name" -Managedby $_.name
}
您可以一次性全部指定
To enter multiple values and overwrite any existing entries, use the
following syntax: value1,value2
Source: Set-DistributionGroup @ Technet
样本:
set-distributiongroup -identity "group name" -Managedby (Import-Csv "path to file" | Select-Object -ExpandProperty Name)
或者您可以使用键值对来添加或删除特定用户(无需替换所有成员)。
To add or remove one or more values without affecting any existing
entries, use the following syntax: @{Add="",""...;
Remove="",""...}.
Source: Set-DistributionGroup @ Technet
样本:
set-distributiongroup -identity "group name" -Managedby @{Add=(Import-Csv "path to file" | Select-Object -ExpandProperty Name)}
或
Import-Csv "path to file" | ForEach-Object {
set-distributiongroup -identity "group name" -Managedby @{Add=$_.name}
}
所有样本都未经测试。
我在为通讯组添加多个由用户管理时遇到问题。该命令运行良好,但是当我去检查发行版组中的用户管理时,唯一添加的人是 csv 文件列表中的最后一个人。我使用了同一个文件来添加成员,所以我不确定为什么它不起作用。
这就是我 运行
import-csv "path to file" | foreach {set-distributiongroup -identity "group name" -Managedby $_.name}
我做错了什么吗? Google 今晚不是我的朋友。
您每次都在覆盖现有值。循环中的最后一个用户将成为管理员。
Import-Csv "path to file" | ForEach-Object {
set-distributiongroup -identity "group name" -Managedby $_.name
}
您可以一次性全部指定
To enter multiple values and overwrite any existing entries, use the following syntax: value1,value2
Source: Set-DistributionGroup @ Technet
样本:
set-distributiongroup -identity "group name" -Managedby (Import-Csv "path to file" | Select-Object -ExpandProperty Name)
或者您可以使用键值对来添加或删除特定用户(无需替换所有成员)。
To add or remove one or more values without affecting any existing entries, use the following syntax: @{Add="",""...; Remove="",""...}.
Source: Set-DistributionGroup @ Technet
样本:
set-distributiongroup -identity "group name" -Managedby @{Add=(Import-Csv "path to file" | Select-Object -ExpandProperty Name)}
或
Import-Csv "path to file" | ForEach-Object {
set-distributiongroup -identity "group name" -Managedby @{Add=$_.name}
}
所有样本都未经测试。