3

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

0

2 Answers 2

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.

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

7
  • @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. Commented Apr 1, 2018 at 3:47
  • 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? Commented Apr 2, 2018 at 4:22
  • I also tried putting your provided code into my default PowerShell profile and ended up with this strange result: 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. Commented Apr 2, 2018 at 4:41
  • @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. Commented Apr 2, 2018 at 12:25
  • 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. Commented Jul 2, 2018 at 4:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .