无法在工作流内使用Add-DistributionGroupMember cmdlet

时间:2017-03-29 15:22:32

标签: powershell exchange-server powershell-workflow

我正在尝试在PowerShell脚本中使用foreach -parallel构造。该脚本如下:

    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 
}

脚本执行返回错误:

  

术语&#39; Add-DistributionGroupMember&#39;不被识别为cmdlet,函数,脚本文件或可操作程序的名称。检查名称的拼写,或者如果包含路径,请验证路径是否正确,然后重试。

任何人都可以帮助我在工作流程中使用Add-DistributionGroupMember cmdlet

0 个答案:

没有答案