在PowerShell中使用工作流会话时命令消失了

时间:2014-04-23 12:55:28

标签: powershell powershell-remoting powershell-workflow

在powershell中使用工作流会话时,似乎最常见的命令已经消失了:

PS P:\> $session = New-PSWorkflowSession -ThrottleLimit 3
PS P:\> Invoke-Command $session {Write-Output "test"}

The term 'Write-Output' is not recognized as the name of a cmdlet, function, script
file, or operable program. Check the spelling of the name, or if a path was included,
verify that the path is correct and try again.
 + CategoryInfo         : ObjectNotFound: (Write-Output:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
+ PSComputerName        : localhost

如何通过会话提供工作流程中通常可用的所有常用命令?

1 个答案:

答案 0 :(得分:0)

由于您正在使用工作流会话,因此您需要将命令放在工作流程中。

$session = New-PSWorkflowSession -ThrottleLimit 3

Invoke-Command $session {
        workflow test {
            Write-Output -Input "test"
        }
        test
    }

有关详细信息,请查看PowerShell Workflows: RestrictionsHigh Level Architecture of Windows PowerShell Workflow (Part 1)