How to log to Powershell console from Workflow Job

3.4k Views Asked by At

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.

1

There are 1 best solutions below

0
On

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.