PowerShell工作流调用命令不工作(写入主机)

PowerShell工作流调用命令不工作(写入主机),powershell,remote-access,workflow-foundation,invoke-command,powershell-workflow,Powershell,Remote Access,Workflow Foundation,Invoke Command,Powershell Workflow,目前正在尝试使用PowerShell工作流来处理一些我正在并行执行的远程服务器工作 我无法让Invoke命令登录到服务器以实际工作。它不会抛出错误,但也不会像通常使用Write Host语句那样输出到控制台。没有看到任何有助于我浏览旧帖子的东西 workflow test { Param([System.Management.Automation.PSCredential]$cred) InlineScript { Write-Host $using:cred

目前正在尝试使用PowerShell工作流来处理一些我正在并行执行的远程服务器工作

我无法让
Invoke命令
登录到服务器以实际工作。它不会抛出错误,但也不会像通常使用
Write Host
语句那样输出到控制台。没有看到任何有助于我浏览旧帖子的东西

workflow test {
    Param([System.Management.Automation.PSCredential]$cred)

    InlineScript {
        Write-Host $using:cred
        Invoke-Command -Computer "server" -Credential $using:cred  -ScriptBlock { Write-Host "hello world" } }
    }
}

#Calling the function
test $cred

写输出而不是写主机工作。请注意,这也是并行运行的:

invoke-command computer1,computer2,computer3 { 'whatever' } 
顺便说一句,你有一个额外的卷曲括号结束

另一种方法是:

workflow test {
  InlineScript {
    Write-Host 'hello world'
  }
}

test -pscomputername server -pscredential $cred

写输出而不是写主机工作。请注意,这也是并行运行的:

invoke-command computer1,computer2,computer3 { 'whatever' } 
顺便说一句,你有一个额外的卷曲括号结束

另一种方法是:

workflow test {
  InlineScript {
    Write-Host 'hello world'
  }
}

test -pscomputername server -pscredential $cred

不要仅仅为了并行运行而使用工作流(可以通过作业或运行空间来实现)。不仅工作流明显比常规PowerShell慢,而且对于普通PowerShell,b/c工作流也在不同的引擎中运行。当你知道自己在做什么时,工作流是有用的,但不要仅仅因为知道而使用工作流。@AnsgarWiechers谢谢你!事实证明,这是一个更加优雅的解决方案,而且我喜欢这样一个事实,即它将所有内容都保留在powershell环境中。不要使用工作流来并行运行东西(可以通过作业或运行空间来实现)。不仅工作流明显比常规PowerShell慢,而且对于普通PowerShell,b/c工作流也在不同的引擎中运行。当你知道自己在做什么时,工作流是有用的,但不要仅仅因为知道而使用工作流。@AnsgarWiechers谢谢你!事实证明,这是一个更加优雅的解决方案,我喜欢这样一个事实,即它将所有内容都保留在powershell环境中。