I'm attached to the nice blue colour of the PowerShell window when you launch it from one of the pre-installed shortcuts. However, if you manually launch powershell.exe, you don't get these colours, you get black/white :(
This is because the default settings are set on the shortcut (.lnk) file:
I've got a "PowerShell Prompt Here" entry in Explorer context menu, and I'd like it to launch PowerShell using the same nice colours as the usual shortcut; black sucks, and it's confusing to have different coloured windows (especially when I have some old-school command windows open frequently that are also black!).
I've found two problems with trying to set this so far:
Is there any way to launch PowerShell from a command line (ie. that I can embed in the registry as an Explorer context menu item) that will use the same settings as the shortcut?
Introduction to Changing Colors in PowerShell The colors are set for the Warnings, Errors, Debug, Verbose, and Progress streams inside the $host. PrivateData object. Try changing one of these values and seeing if your console also changes colors. The error background default color "black" will change to "white" .
When the Open with dialog box appears, drill down to the directory C:\Windows\System32\WindowsPowerShell\v1. 0 and select the powershell.exe file. Click Open. Now you've successfully set PowerShell as the default program for opening .
As mentioned above, the number of colors you can choose from is somewhat limited: Black, DarkBlue, DarkGreen, DarkCyan, DarkRed, DarkMagenta, DarkYellow, Gray, DarkGray, Blue, Green, Cyan, Red, Magenta, Yellow, and White.
Edit your profile script (pointed to by $profile) and set the desired colors yourself:
# set regular console colors [console]::backgroundcolor = "darkmagenta" [console]::foregroundcolor = "darkyellow" # set special colors $p = $host.privatedata $p.ErrorForegroundColor = "Red" $p.ErrorBackgroundColor = "Black" $p.WarningForegroundColor = "Yellow" $p.WarningBackgroundColor = "Black" $p.DebugForegroundColor = "Yellow" $p.DebugBackgroundColor = "Black" $p.VerboseForegroundColor = "Yellow" $p.VerboseBackgroundColor = "Black" $p.ProgressForegroundColor = "Yellow" $p.ProgressBackgroundColor = "DarkCyan" # clear screen clear-host
Here's a really easy way:
Start -> run "sysdm.cpl" -> advanced -> Environment Variables
Scroll Down through system variables, double click PATHEXT
Add .LNK; as depicted below:
Copy-Item "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Accessories\Windows PowerShell\Windows PowerShell.lnk" "C:\Windows\System32\powershell.lnk"
You can further customize the .lnk in C:\Windows\System32 to your liking.
Please note that this will only work because you have added the .lnk to the list of acceptable extensions AND c:\windows\system32 is the first item in the search path (PATH system variable) by default.
This will not customize the console if it is launched via cmd.exe.
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Directory\shell\PowerShellHere\command] @="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\"" [HKEY_CLASSES_ROOT\Directory\shell\PowerShellHere\command] @="C:\\WINDOWS\\system32\\cmd.exe /c start powershell -NoExit \"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'\""
I am using cmd.exe to call "start" which will launch the powershell.lnk and pass the current working directory as an argument. Doesn't seem to work from the address bar yet. I should have gone home 45mins ago, but your problem was fun to solve! :)
Bonus Points: You can thread the commands sent to Powershell. So, if you are looking to modify the Powershell console's title attribute:
\"cd '%1';(get-host).ui.rawui.windowtitle = 'Oompa Loompa'"
Simply add a semicolon between commands.
Happy shelling
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