Support for `foregroundcolor` inside PS script

Aleksander Sjåfjell's Avatar

Aleksander Sjåfjell

24 Oct, 2016 10:16 AM

It seems that the flag `foregroundcolor` for PowerShell only works directly within a `- ps:` build script. Using the flag within a loaded powershell script file does not give colored output. I have tested with simple output like this: `Write-Host -foregroundcolor green "My successful message"`. Is there some magic to get this behaviour within a powershell script like `powershell .\MyScript.ps1`? All help appreciated.

  1. Support Staff 1 Posted by Ilya Finkelshte... on 24 Oct, 2016 08:22 PM

    Ilya Finkelshteyn's Avatar

    Hi Aleksander,

    You can call it this way to use .ps1 script and still have foregroundcolor displayed:

     ps: .\MyScript.ps1
    

    Will it work for you or for some reason you have to call it only from cmd?

    Thank you,
    Ilya.

  2. 2 Posted by hubert.bukowski on 12 Jan, 2018 10:08 AM

    hubert.bukowski's Avatar

    Hi,
    I know that this thread is pretty old but I have similar problem.
    In my case I am using single cmd script for CI and for regular manual build. This script tries to find PowerShell Core in requested version (for example 6.0.0-rc.2) and installs it if not found. Then it runs ps1 script. In this scenario all output from pwsh.exe has default console color.

    Logs:
    https://ci.appveyor.com/project/Leet/buildtools/build/0.0.2.74-master
    For comparison Travis output:
    https://travis-ci.org/hubuk/BuildTools/jobs/327614980

  3. Support Staff 3 Posted by Ilya Finkelshte... on 12 Jan, 2018 10:37 PM

    Ilya Finkelshteyn's Avatar

    @hubert.bukowski unfortunately this is by design right now. We are adding PowerShell Core support so probably next week you can simple use - pwsh: prefix to run it as is. But it still will be colorless, sorry.

  4. 4 Posted by hubert.bukowski on 12 Jan, 2018 11:01 PM

    hubert.bukowski's Avatar

    Thank you for the response. For me it would be best to have full control over the version of pwsh installed so I will need to stay with cmd.
    Fortunately I found a workaround. I'm using ANSI escape sequences for colors when run on AppVeyor and regular -ForegroundColor otherwise:
    https://ci.appveyor.com/project/Leet/buildtools/build/0.0.2.83-master

  5. Support Staff 5 Posted by Ilya Finkelshte... on 12 Jan, 2018 11:08 PM

    Ilya Finkelshteyn's Avatar

    This is amazing! Thanks a lot for the idea :)

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac

 

18 Aug, 2018 11:54 AM
18 Aug, 2018 12:13 AM
17 Aug, 2018 06:02 PM
17 Aug, 2018 04:26 PM
17 Aug, 2018 04:04 PM
17 Aug, 2018 06:31 AM