Setting Powershell colors with hex values in profile script

前端 未结 5 1418
旧时难觅i
旧时难觅i 2021-01-11 17:09

I know I can change PowerShell console colors by setting in my profile something like:

$Host.UI.RawUI.BackgroundColor = \"White\"
Clear-Host
<
相关标签:
5条回答
  • 2021-01-11 17:29

    You can, but not via the $Host object. The color table is stored in the registry.

    You would use the same names, but the colors would be different. That's why the default PowerShell console is blue/gray.

    0 讨论(0)
  • 2021-01-11 17:32

    I doubt that's possible. The $Host.UI.RawUI.BackgroundColour is a System.ConsoleColor enumerator, thus there's only a finite set of colours that you could select. http://msdn.microsoft.com/en-GB/library/system.consolecolor.aspx

    0 讨论(0)
  • 2021-01-11 17:36

    For anyone that may be looking to custom color the Powershell ISE here is the format.

    #Get the list of colors and hex equivalents
     [windows.media.colors] | Get-Member -Static -MemberType property | 
    ForEach-Object { 
    $psISE.Options.ConsolePaneTextBackgroundColor = `
    ([windows.media.colors]::$($_.name)).tostring() 
    “$($_.name) `t $([windows.media.colors]::$($_.name))” 
    }
    
    #Example of how to change the console color in the powershell ISE
    $psISE.Options.ConsolePaneBackgroundColor = '#FF4169E1'  #RoyalBlue
    $psISE.Options.ConsolePaneTextBackgroundColor = '#00FFFFFF'  #Transparent  
    

    Proper credit belongs to "The scripting Guy", sorry I don't have the link but the code is directly from his website.

    0 讨论(0)
  • 2021-01-11 17:49

    The correct way to do this is with the Registry

    cd hkcu:/console
    $0 = '%systemroot%_system32_windowspowershell_v1.0_powershell.exe'
    ni $0 -f
    sp $0 ColorTable00 0x00562401
    sp $0 ColorTable07 0x00f0edee
    

    With the color being

    0x00BBGGRR
    
    0 讨论(0)
  • 2021-01-11 17:53

    As far as I know, you can't. The console API doesn't support custom color. If you do this:

    $x = (Get-Host).UI.RawUI
    $x | gm
    

    you'll see that BackgroundColor is of type System.ConsoleColor.

    0 讨论(0)
提交回复
热议问题