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?!
Current foreground and background can be obtained like this.
PS>(get-host).ui.rawui.ForegroundColor
Gray
PS>(get-host).ui.rawui.BackgroundColor
Black
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With