Write-Error not showing errors?

Product: PowerShell Universal
Version: 2.11.1
$User = "First.last@domain.com"
Write-Host "Here is some host output"
Write-Error "Failed to find UserPrincipalName [ $User ]"

It used to work?

What’s your scripts ErrorAction set to? It might be hiding the error if it’s set to SilentlyContinue. You could change it to Continue.

This is literally the script…

$User = "First.last@domain.com"
Write-Host "Here is some host output"
Write-Error "Failed to find UserPrincipalName [ $User ]"


At some point we started to actually set ErrorActionPreference based on that setting and then it suppresses the error messages. If you change it to continue, it should show them.

Looks like that worked. I tend to check various scripts output types to handle errors from other PS processes. So when it was being suppressed the errors were slipping through.

    # Return all errors
    $JobError = $HostOutput | Where-Object { 
        $_.Type -eq [PSUJobOutputTypes]::Error 

Not sure if this is the best way to handle this but its been working I guess…

Any idea why the errors tend to show up multiple times?

Now that seems like a bug. I’ll open an issue for it.

Appreciate the quick reply.

Ill set my scripts -ErrorAction “Continue” across the board.

1 Like


So we upgraded to version 2.12.2 and write-error with ErrorAction set to continue is not showing that the job failed? Is this intended?

However on version 3.0.0 it shows the job failed with that same ErrorAction preference.

I guess I’m not sure what is intended here. I would like to see the job failed when write-error happens so we can utilize triggers. This worked in version 2.11.1


The expected behavior is that Continue will not fail but will display errors. SilentlyContinue will not display errors or fail. Stop will fail the script and display errors.

I think the v3 behavior is incorrect.

Thanks for the quick reply. For our case we might want to set the ErrorAction to stop if that is the case.