管道未执行,因为管道已在执行

时间:2018-03-15 04:31:17

标签: powershell

尝试运行脚本时,我收到以下错误消息:

这是我的剧本:

$saveto = "C:\scripts\Distribution Groups.txt"
filter get_member_recurse {
    if($_.RecipientType -eq "MailUniversalDistributionGroup") {
        Get-DistributionGroupMember -ResultSize "Unlimited" $_.Name | get_member_recurse
    } else {
    $output = $_.Name + " (" + $_.PrimarySMTPAddress + ")"
    Write-Output $output
    }
} 
$DistributionGroup = Get-DistributionGroup | Sort-Object Name | ForEach-Object {
    "`r`n$($_.DisplayName) ($($_.PrimarySMTPAddress))`r`n=============" | Add-Content $saveto
    $distout = Get-DistributionGroupMember -ResultSize "Unlimited" $_.Name | get_member_recurse
    Write-Output $distout | Sort-Object | Get-Unique  | Add-Content $saveto
}

错误讯息:

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

Pipeline not executed because a pipeline is already executing. Pipelines cannot be executed concurrently.
    + CategoryInfo          : OperationStopped: (Microsoft.Power...tHelperRunspace:ExecutionCmdletHelperRunspace) [], PSInvalidOperationException
    + FullyQualifiedErrorId : RemotePipelineExecutionFailed

提前致谢

3 个答案:

答案 0 :(得分:0)

也许这就是你要找的东西?

$saveto = 'C:\temp\Distribution Groups.txt'
function get_member_recurse {
    Param([array]$Members)
    foreach ($Member in $Members) {
        if($Member.RecipientType -eq "MailUniversalDistributionGroup") {
           get_member_recurse (Get-DistributionGroupMember -ResultSize "Unlimited" $Member.Name)
        } else {
            [array]$output += $($Member.DisplayName + " (" + $Member.PrimarySMTPAddress + ")")
        }
    }
    return $output
}

$DistributionGroups = Get-DistributionGroup | Sort-Object Name
foreach ($dg in $DistributionGroups) {
    "`n$($dg.DisplayName) ($($dg.PrimarySMTPAddress))`n=============" | Out-File -FilePath $saveto -Append
    [array]$distout += get_member_recurse (Get-DistributionGroupMember -ResultSize "Unlimited" $dg.Name)
    $distout = $distout | Sort -Unique 
    $distout | Out-File -FilePath $saveto -Append
}

答案 1 :(得分:0)

这里有同样的事情,但有进度条!! ; - )

$saveto = 'C:\temp\Distribution Groups.txt'

function get_member_recurse {
    Param([array]$Members)
    foreach ($Member in $Members) {
        if($Member.RecipientType -eq "MailUniversalDistributionGroup") {
           get_member_recurse (Get-DistributionGroupMember -ResultSize "Unlimited" $Member.Name)
        } else {
            [array]$output += $($Member.DisplayName + " (" + $Member.PrimarySMTPAddress + ")")
        }
    }
    return $output
}

$DistributionGroups = Get-DistributionGroup | Sort-Object Name
foreach ($dg in $DistributionGroups) {
    write-Progress -Activity "Parsing Distribution Groups Recursively - $($DistributionGroups.IndexOf($dg)) of $($DistributionGroups.Count)" -status "$($dg.DisplayName) ($($dg.PrimarySMTPAddress))" -PercentComplete ($DistributionGroups.IndexOf($dg) / $DistributionGroups.count*100)
    "`n$($dg.DisplayName) ($($dg.PrimarySMTPAddress))`n=============" | Out-File -FilePath $saveto -Append
    [array]$distout += get_member_recurse (Get-DistributionGroupMember -ResultSize "Unlimited" $dg.Name)
    $distout = $distout | Sort -Unique 
    $distout | Out-File -FilePath $saveto -Append
}

答案 2 :(得分:0)

最近遇到此错误,最终发现它来自FOREACH(或|%{})命令中的错误

最简单的解决方法是在对象进入foreach之前包装它们

更改此内容:

one-command|two-command|%{stuff}

对此:

@(one-command|two-command)|%{stuff}

@()将它们收集到一个数组中