Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell get default foreground color for write-host

Tags:

powershell

I have a function to write an output log to file and to console. The Write-Host part I'd like to color up a bit ;-)

switch($logLevel)
{
   "FATAL" { $ConsoleWriteColor = "blue"; break }
   "ERROR" { $ConsoleWriteColor = "red"; break }
   "WARN" { $ConsoleWriteColor = "yellow"; break }
   default { $ConsoleWriteColor = "white"; break }

}
Write-Host -ForegroundColor $ConsoleWriteColor "Hello world"

So my question is for the default case: How can I get the current foreground color? I guess it will not always be white?!

like image 417
silent Avatar asked Oct 27 '14 07:10

silent


1 Answers

Current foreground and background can be obtained like this.

PS>(get-host).ui.rawui.ForegroundColor
Gray
PS>(get-host).ui.rawui.BackgroundColor
Black
like image 198
hysh_00 Avatar answered Oct 13 '22 20:10

hysh_00