Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 是否向多个用户授予“作为发送”或“作为代表发送”权限?_Powershell - Fatal编程技术网

Powershell 是否向多个用户授予“作为发送”或“作为代表发送”权限?

Powershell 是否向多个用户授予“作为发送”或“作为代表发送”权限?,powershell,Powershell,我想同时向多个用户授予“作为发送”和/或“作为代表发送”权限。 现在,我可以通过下面的脚本逐个授予权限 我的CSV文件: "DisplayName","PrimarySMTPAddress","SendAsPermissions","SendOnBehalfPermissions" "DG01","DG01@contoso.com","CONTOSO\Ituser01

我想同时向多个用户授予“作为发送”和/或“作为代表发送”权限。 现在,我可以通过下面的脚本逐个授予权限

我的CSV文件:

"DisplayName","PrimarySMTPAddress","SendAsPermissions","SendOnBehalfPermissions"
"DG01","DG01@contoso.com","CONTOSO\Ituser01;CONTOSO\Ituser02;CONTOSO\Ituser03","user01@contoso.com;user02@contoso.com"
"DG02","DG02@contoso.com","","user11@contoso.com;user42@contoso.com"
"DG03","DG03@contoso.com","CONTOSO\Ituser34",""
脚本:

$importDLs = Import-Csv -Path C:\TEMP\delegate.csv

foreach ($importDL in $importDLs){

$importDL.SendAsPermissions
$importDL.SendOnBehalfPermissions


#Grant a user Send-On-Behalf to a distribution group so they can Send-on-behalf of the distribution group.
Set-DistributionGroup -Identity "$importDL.PrimarySMTPAddress" -GrantSendOnBehalfTo @{add="$importDL.SendOnBehalfPermissions"}

#Grant a user Send As permissions to a distribution group so they can send as the distribution group
Get-DistributionGroup "$importDL.PrimarySMTPAddress" | Add-ADPermission -User "$importDL.SendAsPermissions" -ExtendedRights "Send As"


}
最近更新:

$importDLs = Import-Csv -Path C:\TEMP\delegate.csv

foreach ($importDL in $importDLs){

$importDLSendAs2 = $importDL.SendAsPermissions -split ";"
$importDLSendAsBehalf2 = $importDL.SendOnBehalfPermissions -split ";"
$dgmail=$importDL.PrimarySMTPAddress


foreach ($importDLSendAs in $importDLSendAs2) {
$domain,$importDLSendAsUser = $importDLSendAs.split('\')
$importDLSendAsUser

#Grant a user Send As permissions to a distribution group so they can send as the distribution group
Get-DistributionGroup "$dgmail" | Add-ADPermission -User "$importDLSendAsUser" -ExtendedRights "Send As"


}

foreach ($importDLSendAsBehalf in $importDLSendAsBehalf2) {

#Grant a user Send-On-Behalf to a distribution group so they can Send-on-behalf of the distribution group.
Set-DistributionGroup -Identity "$dgmail" -GrantSendOnBehalfTo @{add="$importDLSendAsBehalf"}


}



}

您的问题是什么?我想同时向多个用户授予“作为发送”和/或“作为代表发送”权限。现在,我可以通过脚本逐个授予权限。Re
Set DistributionGroup
:声明“要添加或删除一个或多个值而不影响任何现有条目,请使用以下语法:
@{add=“Value1”、“Value2”…;remove=“Value3”、“Value4”}
”Re
Add ADPermisson
:建议
-User
参数只接受一个值(不接受管道输入)。编辑的代码有什么不适用?我认为您需要将
-grantsendobehalfto
参数的语法更改为
{Add=[string[]]$importDLSendAsBehalf2}
并删除
foreach($importDLSendAsBehalf in$importDLSendAsBehalf2){..
循环,或者从中创建一个逗号分隔的引用电子邮件地址字符串,如
{Add=(($importDLSendAsBehalf2 | ForEach对象{''{0}'-f${})-join',')}
。可以试试吗?