Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PowerShell获取写入主机的默认前景色_Powershell - Fatal编程技术网

PowerShell获取写入主机的默认前景色

PowerShell获取写入主机的默认前景色,powershell,Powershell,我有一个将输出日志写入文件和控制台的函数。写主机部分我想加一点颜色;-) 所以我的问题是关于默认情况:如何获得当前的前景色?我猜它不会永远是白色的 当前前景和背景可以这样获得 PS>(get-host).ui.rawui.ForegroundColor Gray PS>(get-host).ui.rawui.BackgroundColor Black 这对我来说总是-1@安静,你在PowerShell中,对吗?此命令将在本机shell中工作。在那里试试看是的你是对的。。。确实有工作

我有一个将输出日志写入文件和控制台的函数。写主机部分我想加一点颜色;-)


所以我的问题是关于默认情况:如何获得当前的前景色?我猜它不会永远是白色的

当前前景和背景可以这样获得

PS>(get-host).ui.rawui.ForegroundColor
Gray
PS>(get-host).ui.rawui.BackgroundColor
Black

这对我来说总是-1@安静,你在PowerShell中,对吗?此命令将在本机shell中工作。在那里试试看是的你是对的。。。确实有工作,但当文本明显为白色时,它会说DarkYellow?!看起来DarkYellow的名字错了。这里讨论这个问题。当我在Powershell ISE(v5.1.14409.1012)中运行此命令时,它返回
-1
,该命令不会强制转换为
[System.ConsoleColor]
。这意味着这将失败:
Write Host-ForegroundColor([System.ConsoleColor]-1)“Hello world”
PS>(get-host).ui.rawui.ForegroundColor
Gray
PS>(get-host).ui.rawui.BackgroundColor
Black