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:
- Setting the colour from within PowerShell seems to only allow certain values (ConsoleColor enum), none of which match the one on the default shortcut.
- Setting the colour within the PS Profile causes only text written afterwards to honour the new background colour. Adding "cls" causes a nasty flash of the original colour as it starts.
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?
Based on @rex-hardin excellent answer, I improved the regedit content here to add an icon, and use the PowerShell native arguments to start in the right path.
The context-menu is enabled when right-clicking on a directory background, and when right-clicking directly on a directory icon.
Of course, we also run a console with blue background exactly like the default one.
1. Add "
.LNK
" extension to%PATHEXT%
environment variableThis allows system to execute files with
.lnk
extension (hidden extension for shortcuts)2. Copy the default PowerShell shortcut link to system32 as
powershell
fileThis allows the
powershell
command to launch our shortcut fromsystem32
folder (which is in%PATH%
)Use explorer (copy+rename) or the command-line below:
3. Add code below to a
powershell_here.reg
file and execute it.powershell_here.reg
Here's a really easy way:
1. Add .LNK to your PATHEXT variable.
Start -> run "sysdm.cpl" -> advanced -> Environment Variables
Scroll Down through system variables, double click PATHEXT
Add .LNK; as depicted below:
2 Copy the default "Windows Powershell.lnk"
3. Typing "powershell" from a run prompt will now bring up the default console color/configuration.
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.
4. To make this work from the "Run Powershell Here" context menu, save this as a .reg file and import it:
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:
Simply add a semicolon between commands.
Happy shelling