Wednesday, 15 July 2015

PowerShell get default foreground color for write-host -



PowerShell get default foreground color for write-host -

i have function write output log file , console. write-host part i'd color 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 question default case: how can current foreground color? guess not white?!

current foreground , background can obtained this.

ps>(get-host).ui.rawui.foregroundcolor grayness ps>(get-host).ui.rawui.backgroundcolor black

powershell

No comments:

Post a Comment