Backup Modified PowerShell Console Colors Properties (Windows 10)

4

I don't quite understand how this works. So when I open up PowerShell as administrator, I can right click on the title bar, go to "Properties," then go to "Colors" and make changes. For example, I set the "Screen Background" default color to black instead of the default dark blue. I've noticed that these changes seem to persist even after I restart the computer and open up PowerShell as administrator again. However, these changes do not seem to apply to whenever I open up PowerShell regularly (not as administrator). So, for example, I could have admin powershell have a black background and regular powershell have a red background.

But here's the point; suppose I change a lot of the colors and I want to back these changes up somehow. They must be stored somewhere, and clearly it's different for each of the two versions of PowerShell, so where are these properties stored, for both versions? Is there an easy way to back them up and restore them at a later date if future changes have been made? If not, is it possible to keep these seetings in my PowerShell profile somehow?

enter image description here

ereHsaWyhsipS

Posted 2018-04-01T02:24:42.450

Reputation: 403

Answers

1

The color settings are stored in the powershell shortcut.

Each user has their own shortcut in C:\Users\[User]\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Windows PowerShell

You can create multiple shortcuts to powershell with different font/color settings by looking at the properties panel for that shortcut.

You can save the shortcut anywhere, and even use it on other computers with the color and font settings saved.

mt025

Posted 2018-04-01T02:24:42.450

Reputation: 2 392

1

Backup Settings

As per the Get-Host documentation, to export these settings to a backup file, etc. you could use something such as (Get-Host).UI.RawUI | Format-List -Property * and put that in an -OutFile.

PS C:\> (Get-Host).UI.RawUI | Format-List -Property *
ForegroundColor       : DarkYellow
BackgroundColor       : DarkBlue
CursorPosition        : 0,390
WindowPosition        : 0,341
CursorSize            : 25
BufferSize            : 120,3000
WindowSize            : 120,50
MaxWindowSize         : 120,81
MaxPhysicalWindowSize : 182,81
KeyAvailable          : False
WindowTitle           : Windows PowerShell 2.0 (04/11/2008 00:08:14)

source

Restore Settings

You can then create a PowerShell script to set these important settings you use explicitly and simply execute that script when you open any new PowerShell session.

(Get-Host).UI.RawUI.ForegroundColor = "DarkYellow"
(Get-Host).UI.RawUI.BackgroundColor = "DarkBlue"
(Get-Host).UI.RawUI.CursorPosition = @{ X = 0; Y = 390 }
(Get-Host).UI.RawUI.WindowPosition = @{ X = 0; Y = 341 }
(Get-Host).UI.RawUI.CursorSize = 25
(Get-Host).UI.RawUI.BufferSize = new-object System.Management.Automation.Host.Size(120,3000)
(Get-Host).UI.RawUI.WindowSize = new-object System.Management.Automation.Host.Size(120,50)
(Get-Host).UI.RawUI.WindowTitle = "Windows PowerShell 2.0"

enter image description here

enter image description here


Further Resources

Pimp Juice IT

Posted 2018-04-01T02:24:42.450

Reputation: 29 425

@ereHsaWyhsipS Let me know if there are any specific settings which I did not include that you need help figuring out how to backup and restore and I'll try to further assist if needed and it's possible. – Pimp Juice IT – 2018-04-01T03:47:08.460

Sorry that I was unable to reply sooner, but I didn't get to test this until just now. So once I have exported the settings to an outfile, as you mentioned at first, I'm not sure how to get to the next step; how would I easily convert all of these settings into a script that would continue to affect all future PowerShell sessions after running? – ereHsaWyhsipS – 2018-04-02T04:22:30.410

I also tried putting your provided code into my default PowerShell profile and ended up with this strange result: https://image.ibb.co/fCBwx7/Screenshot_1.png I got the same result when just running the code as a script directly. I'm not sure what I have been doing wrong.

– ereHsaWyhsipS – 2018-04-02T04:41:48.150

@ereHsaWyhsipS When you get a chance, tell me if there are any specific settings of importance that you want to apply to other sessions and what those may be. I know you have a screen shot of the screen backup colors tab with all "0" values but I wasn't sure if there were other settings of more importance, etc. that I could do some testing with to see if I can get those correct? I need to do more testing but did you see the answer by mt025 and checked whether or not that is easier and works as expected? I want to help you get a working solution but will dig more one I hear back. – Pimp Juice IT – 2018-04-02T12:25:26.340

Hey, I found that they're also located in the registry editor. Check this key out: [HKEY_CURRENT_USER\Console%SystemRoot%_System32_WindowsPowerShell_v1.0_powershell.exe] and, whenever running from the start menu and the keyboard shortcut Alt+F+S+A, the colors are stored in: %AppData%\Microsoft\Windows\Start Menu\Programs\Windows PowerShell\Windows Powershell.lnk – jippyjoe4 – 2018-07-02T03:54:39.987

@jippyjoe4 Have you tested anything with that key to see if it actually does anything or works? – Pimp Juice IT – 2018-07-02T03:57:33.010

1@PimpJuiceIT, restoring the backed up .reg file created by exporting that key indeed does restore the console window properties, but ONLY when running PowerShell directly from the .exe file, NOT from the shortcut; whenever using Alt+F+S+A or using the Windows Search to reach PowerShell, you have to backup the shortcut file itself located at AppData path mentioned in my earlier comment. – jippyjoe4 – 2018-07-02T04:01:47.713