Capture the Executing output

Hi

Is it possible to capture the output of the tests. - Like below?

Executing script .\Pester_Validate_Environment.Pester.test.ps1

  Describing Environment Validation

    Context Testing Environment
      [+] Can generate a security token 440ms
      [+] Can login 357ms
      [+] Can resolve internal links 530ms
Tests completed in 1.33s
Tests Passed: 3, Failed: 0, Skipped: 0, Pending: 0, Inconclusive: 0

Pester uses Write-Host for that output, which historically has meant the answer is “no.”

However, in PowerShell v5+, Write-Host now uses the new information output stream. You can use a redirection operator to accomplish what you’re looking for:

$results = Invoke-Pester 6>&1
$results

That method doesn’t acknowledge the -NoNewLine parameter of Write-Host, but I think it’s as close as you’ll get with Write-Host.

If you want to show output to console as well as to a variable, use -InformationVariable common parameter.

I would suggest you to use the built in output capabilities of pester. Pester can give detailed results in NunitXMl format and the can be used by different nunit readers to build beautiful html reports.

Get-Help Invoke-Pester -ShowWindow #search for examples