Skip to content

Write-Host ForegroundColor error on Linux: "-1 is not a valid color" #372

@divijsehgal

Description

@divijsehgal

When running the PowerShell script on Linux using PowerShell (pwsh), the script throws the following error:

Write-Host: Cannot process the color because -1 is not a valid color. (Parameter 'value')

This happens because the script uses:

as the default value for -ForegroundColor in Write-Host.
In some Linux or non-interactive environments (for example CI/CD pipelines), System.Console::ForegroundColor returns -1, which is not a valid ConsoleColor value.

As a result, Write-Host fails when the script tries to use this value.

Can we add a condition to enforce a color in case ForegroundColor is not set.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions