简体   繁体   中英

How to log to Powershell console from Workflow Job

I have a Powershell workflow. 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. When I execute this workflow with -Verbose switch, verbose logs are displayed on the console as expected.

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 .

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 :

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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