How to configure Powershell or CMD via config file or command line?

gx 1 Reputation point
2022-04-10T12:04:59.283+00:00

我想修改 Powershell 和 CMD 的默认样式,如字体和颜色。但每次都需要在 GUI 中使用很不方便地逐项修改,这很不方便。

Powershell 或 CMD 能否通过配置文件或命令进行修改?

比如,我需要将 Powershell 的配色修改为类 Dracula 主题,使用以下 8 组 RGB,不考虑深浅色:
40 189 80 139 255 255 241 248
42 147 250 233 85 121 250 248
54 249 123 253 85 198 140 242

如果你感觉上面的 RGB 表有些凌乱,很抱歉,这就是 Powershell 或 CMD 的颜色配置方式:只能逐个输入 RGB,却不能使用 HEX。

[translate by google]
I want to modify the default styles of Powershell and CMD like fonts and colors. But every time it needs to be used in the GUI to modify item by item, which is very inconvenient.
Can Powershell or CMD be modified via a config file or command?
For example, I need to change the color scheme of Powershell to a Dracula-like theme, using the following 8 sets of RGB, regardless of shades:
40 189 80 139 255 255 241 248
42 147 250 233 85 121 250 248
54 249 123 253 85 198 140 242
Sorry if the RGB table above is a bit messy to you, this is how Powershell or CMD configure colors: you can only enter RGB one by one, but not HEX.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
11,714 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Limitless Technology 39,676 Reputation points
    2022-04-18T06:45:30.44+00:00

    Hello @gx

    The powershell paletter by command line may not work in the same way.

    For example:
    https://learn.microsoft.com/en-us/powershell/module/psreadline/set-psreadlineoption?view=powershell-5.1 < Customizes the behavior of command line editing
    https://learn.microsoft.com/en-us/powershell/module/psreadline/get-psreadlineoption?view=powershell-5.1 < Gets values for the options that can be configured.

    Additionally for console, you can use a format like this:

    $console = $host.ui.rawui  
    $console.backgroundcolor = "black"  
    $console.foregroundcolor = "white"  
    $colors = $host.privatedata  
    $colors.verbosebackgroundcolor = "Magenta"  
    $colors.verboseforegroundcolor = "Green"  
    $colors.warningbackgroundcolor = "Red"  
    $colors.warningforegroundcolor = "white"  
    $colors.ErrorBackgroundColor = "DarkCyan"  
    $colors.ErrorForegroundColor = "Yellow"  
    set-location C:\  
    clear-host  
    

    Reference for color names: https://learn.microsoft.com/en-us/dotnet/api/system.console.foregroundcolor?view=net-6.0

    Hope this helps with your query,

    ------------

    --If the reply is helpful, please Upvote and Accept as answer--

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.