Is there a way to specify a font color when using write-output

前端 未结 5 1593
抹茶落季
抹茶落季 2021-02-07 02:25

I have a powershell script that gives some status output via write-output. I am intentionally not using write-host because the output may be captured and writt

5条回答
  •  梦毁少年i
    2021-02-07 02:42

    This way:

    function Green
    {
        process { Write-Host $_ -ForegroundColor Green }
    }
    
    function Red
    {
        process { Write-Host $_ -ForegroundColor Red }
    }
    
    Write-Output "this is a test" | Green
    Write-Output "this is a test" | Red
    

提交回复
热议问题