I’m aiming to use PowerShell 7 as much as possible, including in Azure Pipelines tasks. I was getting a bit frustrated recently though where I had a task failing, but the log gave absolutely no clue as to why.

eg.

Starting: MyTask
==============================================================================
Task         : PowerShell
Description  : Run a PowerShell script on Linux, macOS, or Windows
Version      : 2.165.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/powershell
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Program Files\PowerShell\7\pwsh.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\be69a030-2e55-4cb5-9f80-98968e90f3b2.ps1'"
##[error]PowerShell exited with code '1'.
Finishing: MyTask

What’s going on? Turns out it’s because PowerShell 7 now defaults to the ‘ConciseView’ for errors and so the error ends up being so concise it isn’t actually logged. I’m not the first to experience this. The fact that the concise output is not logged at all does look like a bug though.

The solution

Set $ErrorView to ‘NormalView’ as the first line of your script - then you’ll see useful error details that will help with diagnosing what the problem is.

$ErrorView = 'NormalView'

Hopefully in the future, they’ll fix the problem with no errors being logged, or enhance the pwsh task so you can set the ErrorView as a task property outside of the script.

Update 15th May

As Justin mentions in the comments, this problem has been fixed, so no need to prepend your scripts with $ErrorView = 'NormalView' now!