简体   繁体   English

如何从Workflow Job登录Powershell控制台

[英]How to log to Powershell console from Workflow Job

I have a Powershell workflow. 我有一个Powershell工作流程。 I need to log data to Console so that the progress of the workflow is clearly visible. 我需要将数据记录到控制台,以便清楚地看到工作流程的进度。 Till now I used Log-Verbose to achieve this. 直到现在我使用Log-Verbose来实现这一目标。 When I execute this workflow with -Verbose switch, verbose logs are displayed on the console as expected. 当我使用-Verbose开关执行此工作流时, -Verbose预期在控制台上显示详细日志。

workflow Test-Workflow
{
    Log-Verbose "Inside Test-Workflow"
}

Test-Workflow -Verbose

Now I need to use checkpoints inside the workflow. 现在我需要在工作流程中使用检查点。 To take advantage of checkpoints, I need to run the workflow as a Job . 为了利用检查点,我需要将工作流程作为Job运行。

Test-Workflow -Verbose -AsJob

When I do so, I no longer see the verbose logs on the console. 当我这样做时,我不再在控制台上看到详细日志。 I know I can write to a file or write the logs as events but I would really like to write them to the console. 我知道我可以写入文件或将日志写为事件,但我真的想将它们写入控制台。 Let me know if this is possible and how. 如果这是可能的,请告诉我。

I am sure you have discovered a solution to this by now but you can use: 我相信你现在已经发现了一个解决方案但你可以使用:

Write-Output "I will print to the console"

According to MSDN: Write-Output : 根据MSDN:写输出

Sends the specified objects to the next command in the pipeline. 将指定的对象发送到管道中的下一个命令。 If the command is the last command in the pipeline, the objects are displayed in the console. 如果该命令是管道中的最后一个命令,则对象将显示在控制台中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM