写入主机在工作流中的InlineScript中的Invoke-Command中失败

时间:2017-09-14 10:04:54

标签: powershell powershell-workflow

我有这样的事情:

workflow WF {
    foreach -Parallel ($computer in $computers) {
        $results = InlineScript {
            $session = New-PSSession -ComputerName $Using:computer
            return Invoke-Command -Session $session -ScriptBlock {
                 Write-Host "Test"
            }
        }
    }
}

当我运行时,我会收到错误:

A command that prompts the user failed because the host program or the command
type does not support user interaction. Try a host program that supports user
interaction, such as the Windows PowerShell Console or Windows PowerShell ISE,
and remove prompt-related commands from command types that do not support user
interaction, such as Windows PowerShell workflows.
    + CategoryInfo          : NotImplemented: (:) [Write-Host], HostException
    + FullyQualifiedErrorId : HostFunctionNotImplemented,Microsoft.PowerShell.Commands.WriteHostCommand
    + PSComputerName        : [localhost]

如何将Write-Host输出到运行脚本的计算机?请注意,我在ScriptBlock中返回了其他内容,因此我不能只返回字符串并Write-Host

1 个答案:

答案 0 :(得分:0)

您可以使用内联

 inlineScript
    {
    Write-Host "Allow"
    }