zoukankan      html  css  js  c++  java
  • How to Change Error Message Colors in Windows 10 PowerShell Console

    While this was a really easy way to change some of the settings, what if you want to do more extensive changes to your PowerShell console? For example, what if you want to change the text and background colors of error messages from red on black to something a little less drastic? For that, you’ll need to get down and dirty and use the console itself rather than rely on GUI. First off, to know the default colors, go ahead and copy/paste this code on the PowerShell console and press ‘Enter’: $host.privatedata

    To change the foreground and background colors of error messages, all you need to do is assign new values. Since I’d like to change the background color to ‘Magenta’ and foreground color to ‘Green’, I’ll input the two commands below. Just remember to enter them separately and press ‘Enter’ in each case.
    $host.PrivateData.ErrorBackgroundColor = "Magenta"
    $host.PrivateData.ErrorForegroundColor = "Green"

    You have now configured your console settings, but you’ll need to save them to your profile settings so that the screen opens up exactly as you want it to, every time. For that, first run the command $profile. This will show you the name (and location) of the default file for your profile.

    In reality, though, the default PowerShell configuration file does not even exist in most cases. So run the following command to check if it already exists or if you need to create it from scratch: test-path $profile. If the file already exists, you’ll get a “True” output, else, you’ll get “False”.

    As you can see from the above screenshot, I got the latter, so I’ll need to create the file. If you get “True”, skip this step and go to the next. Else, enter the following command to create the file: New-Item -path $profile -type file -force

    Once the file is created, you can easily edit it with Notepad by using the notepad $profile command in the Powershell Window. From there, you can add whatever configuration code you want to using the commands discussed above. You can not only change colors, but also fonts, windows size, etc through this method, but we’re only going to take a look at changing colors without complicating matters any further.

    $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

    We’re almost there, but there’s one last step. Run the following command to permit local scripts to run on your system: Set-ExecutionPolicy RemoteSigned and select “A” to allow all scripts. Now that you’re done, this is how your PowerShell console would look every time you start it up. Even the errors messages would look a little less jarring than they normally do.

    That’s it, folks, I’ve made the Windows PowerShell console on my work laptop look almost exactly like the good old Command Prompt with just a dash of color thrown in for fun.

    Ref:https://beebom.com/how-change-powershell-color-scheme-windows-10/

  • 相关阅读:
    软件工程(2019)第一次作业
    Coding.net主页地址链接
    解决Oracle 11g重建em时报错创建档案资料库时出错以及删除原有em时报监听程序未启动
    解决VirtualBox与锐捷网络冲突的问题
    王道数据结构复习(一)
    第二次结对编程—四则运算自动生成程序
    软件工程(2019)结对编程第一次作业
    软件工程(2019)第三次个人作业——求最大子段和(于VS2017下代码覆盖单元测试)
    软件工程(2019)第二次作业
    软件工程第一次作业
  • 原文地址:https://www.cnblogs.com/seeken/p/10751496.html
Copyright © 2011-2022 走看看