我正在尝试foreach -parallel
在我的 PowerShell 脚本中使用构造。脚本如下:
Param([string]$MAIL_GROUP,
[string]$INPUT_GROUP_MEMBERS_STRING)
Try
{
$ExSession = New-PSSession –ConfigurationName Microsoft.Exchange –ConnectionUri ‘MyExchange’
Import-PSSession $ExSession
Set-ADServerSettings -ViewEntireForest $True
$RealGroupUsers = Get-DistributionGroupMember -Identity $MAIL_GROUP | Select -ExpandProperty Primarysmtpaddress
[System.Collections.ArrayList]$InputGroupUsers = New-Object ([System.Collections.ArrayList])
$INPUT_GROUP_MEMBERS_STRING.Split(';',[System.StringSplitOptions]::RemoveEmptyEntries) | foreach {$InputGroupUsers.Add($_.Trim())} | Out-Null
$InputGroupUsers = $InputGroupUsers | ? { $_ } | sort -uniq
workflow Test-Workflow
{
[CmdletBinding()]
Param ([Parameter(Mandatory=$true,Position=0)]$RealGroupUsers,
[Parameter(Mandatory=$true,Position=1)]$InputGroupUsers)
$emails = Compare-Object -ReferenceObject $RealGroupUsers -DifferenceObject $InputGroupUsers
foreach -Parallel ($email in $emails)
{
if($email.SideIndicator -eq "=>")
{ Add-DistributionGroupMember -Identity $MAIL_GROUP -Member $email.InputObject;}
elseif($email.SideIndicator -eq "<=")
{ Remove-DistributionGroupMember -Identity $MAIL_GROUP -Member $email.InputObject -Confirm:$false;}
}
}
Test-Workflow -RealGroupUsers $RealGroupUsers -InputGroupUsers $InputGroupUsers
Remove-PSSession $ExSession
}
Catch [system.exception]
{
$Error
}
脚本执行返回错误:
术语“Add-DistributionGroupMember”未被识别为 cmdlet、函数、脚本文件或可运行程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确并重试。
任何人都可以帮助我在Add-DistributionGroupMember
工作流程中使用cmdlet 。