Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions