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.
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.