如何以编程方式将Powershell背景颜色设置为RGB值

pra*_*eep 8 console powershell

目前从Console Colors中选择的16种颜色对我来说不是正确的选择.我想在背景中使用这些更暗的变体.

我绝对可以使用UI设置这些并在那里更改RGB值.

选择蓝色并将值更改为65

例如,我可以选择Darkblue并在RGB部分选择65 for Blue(128是默认值).有人可以告诉我如何以编程方式执行此操作.

就像是:

(Get-Host).UI.RawUI.BackgroundColor=DarkBlue
Run Code Online (Sandbox Code Playgroud)

但有额外的选择.

man*_*lds 8

Lee Holmes的这篇老帖子解释了如何将颜色更改为您想要的任何值.您必须更改注册表 - http://www.leeholmes.com/blog/2008/06/01/powershells-noble-blue/

Push-Location 
Set-Location HKCU:\Console 
New-Item ".\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe" 
Set-Location ".\%SystemRoot%_system32_WindowsPowerShell_v1.0_powershell.exe"

New-ItemProperty . ColorTable00 -type DWORD -value 0×00562401 
New-ItemProperty . ColorTable07 -type DWORD -value 0x00f0edee 
New-ItemProperty . FaceName -type STRING -value "Lucida Console" 
New-ItemProperty . FontFamily -type DWORD -value 0×00000036 
New-ItemProperty . FontSize -type DWORD -value 0x000c0000 
New-ItemProperty . FontWeight -type DWORD -value 0×00000190 
New-ItemProperty . HistoryNoDup -type DWORD -value 0×00000000 
New-ItemProperty . QuickEdit -type DWORD -value 0×00000001 
New-ItemProperty . ScreenBufferSize -type DWORD -value 0x0bb80078 
New-ItemProperty . WindowSize -type DWORD -value 0×00320078 
Pop-Location
Run Code Online (Sandbox Code Playgroud)


pol*_*ris 6

这个 powershell 函数模仿了 cmd 行调用: color b0

function Set-ConsoleColor ($bc, $fc) {
    $Host.UI.RawUI.BackgroundColor = $bc
    $Host.UI.RawUI.ForegroundColor = $fc
    Clear-Host
}
Set-ConsoleColor 'cyan' 'black'
Run Code Online (Sandbox Code Playgroud)

可以使用以下代码检索控制台颜色名​​称:

[Enum]::GetValues([ConsoleColor])
Run Code Online (Sandbox Code Playgroud)

  • 这将一直有效,直到输入命令为止。然后它又回到旧的配色方案。 (2认同)