The current selection of 16 colors from Console Colors is not the right choice for me. I would like to use much darker variants of these for the background.
I could definitely set these using the UI and changing the RGB value there.
For example, I could choose Darkblue and select 65 for Blue in the RGB section(128 is the default). Could some one tell me how to do this programmatically.
Something like:
(Get-Host).UI.RawUI.BackgroundColor=DarkBlue
But with additional options.
To change the background color of the font, you can use the GUI and command line both. With GUI − Colors → Screen Background. You will notice that the background color of the text has been changed to DarkBlue.
Console colorsYou can change the general background colors through the $host. ui. rawui object and the colors for errors and warnings through the $Host. PrivateData object.
Copy the ones you want to reset to their default color settings, and paste them in your "C:\Users\User\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell" folder. That's it!
I've added this function to my powershell profile since there is a program that regularly messes up the colors of my shell.
$DefaultForeground = (Get-Host).UI.RawUI.ForegroundColor
$DefaultBackground = (Get-Host).UI.RawUI.BackgroundColor
function SetColors
{
Param
(
[string]$Foreground = "",
[string]$Background = ""
)
$ValidColors = "black","blue","cyan","darkblue" ,"darkcyan","darkgray",
"darkgreen","darkmagenta","darkred","darkyellow","gray","green",
"magenta","red","white","yellow";
$Foreground = $Foreground.ToLower()
$Background = $Background.ToLower()
if ( $Foreground -eq "" )
{
$Foreground = $DefaultForeground
}
if ( $Background -eq "" )
{
$Background = $DefaultBackground
}
if ( $ValidColors -contains $Foreground -and
$ValidColors -contains $Background )
{
$a = (Get-Host).UI.RawUI
$a.ForegroundColor = $Foreground
$a.BackgroundColor = $Background
}
else
{
write-host "Foreground/Background Colors must be one of the following:"
$ValidColors
}
}
set-alias set-colors SetColors
Some notes:
"$DefaultCololrs = (Get-Host).UI.RawUI" creates more of a pointer-type object than an actual copy of the object. This means that if you later set a different variable equal to "(Get-Host).UI.RawUI", and change things, $DefaultColors will also change (which is why I've made sure to copy them here as strings).
I tried setting other colors (using hex codes) with very little luck, though I did find Setting Powershell colors with hex values in profile script (I just haven't tried it yet, since I'm not particularly fond of mucking about in the registry, and the default list of colors seemed rather sufficient).
I also found this document: https://technet.microsoft.com/en-us/library/ff406264.aspx, which I may have to use later to figure out how to modify my "grep" command (currently I have it aliased to select-string)
This old post by Lee Holmes explains how you can go about changing the color to any value you want. You have to change the registry - 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With