I'm trying to launch a PowerShell session via PSexec with alternate colors and some window attributes. The reason why I would need to run PowerShell through PSExec is so that I can have a ready-made one-click shortcut to launch a terminal window in the Local System context. This makes sense for testing scripts and code within MDT/SCCM packages on a daily basis. It sounds like a pointless thing to do but I have a lot of command windows open so it's hard for me to distinguish which terminal windows is running as system, user, local admin, etc. The colors would make it easier to see this difference immediately.

So far I'm trying this, but explorer crashes upon launch:

C:\SysinternalsSuite\psexec.exe /i /s "PowerShell.exe -NoExit -Command "& $HOST.UI.RawUI.ForeGroundColor = cyan"

I can launch PowerShell just fine, like this:

C:\SysinternalsSuite\psexec.exe /i /s powershell.exe

I'm sure it has something to do with the way the quotes are being parsed.

  • I could probably tell PSExec to run a script as system that would define the window attributes as well, but I'm not sure which would be easier. – montag Mar 19 '15 at 15:54
  • 3
    Your path/quotes don't look right. Are you getting any error messages you can share? – Tim Ferrill Mar 19 '15 at 17:04
  • I know the path is right. It really doesn't matter in this case with the quotes in the path, but for a folder like Program Files you would need it. I will update my question to elaborate a little bit. – montag Mar 19 '15 at 19:18
  • So what does happen? Does it launch Powershell with the wrong colour font? Return an error? What is the problem? – Spamwich Mar 19 '15 at 19:45

I figured it out. This is what I did:

1) Created 2 bat files in a folder called C:\Launchers--one for launching CMD as system and one for PS

2) Downloaded the latest version of SysinternalsSuite and placed the folder in C:\

3) Pinned a shortcut to my taskbar and then did the following: A) set the shortcut "Target:" field to: C:\Windows\System32\cmd.exe /C "C:\Launchers\Launch_PS_As_Sys.bat" B) set "Start In:" field to "C:\Launchers". C) clicked "Advanced" and checked "Run as administrator"

The bat file contains this line for the PowerShell System launcher:

C:\SysinternalsSuite\psexec.exe /dis powershell.exe -NoExit -Command "& {cd C:\Users\<yourusername>\Desktop; $HOST.UI.RawUI.ForeGroundColor='Cyan'}"

And this line for CMD Prompt:

C:\SysinternalsSuite\psexec.exe /dis cmd.exe /k "cd C:\Users\<yourusername>\Desktop & Color 0A"

It turns out that the way that the .bat and/or PSExec parse quotes somehow conflict with each other so that you have to use single quotes instead of double quotes. Probably my mistake. Anyway I hope someone finds this useful.


Two things:

  1. You can use Powershell profiles to customize the shell
  2. You can simply change the shell properties (color, font size, buffer) - they persist after all

Both works without having to use external tools like psexec.

Your approach is overly complicated. Just create a shortcut to Powershell, then go open the link's properties and set the "Start in" value to the directory you want to start Powershell with and customize the shell colors via the colors tab. The same works with cmd.exe.

  • I rephrased the question quite a bit to reflect more what I was trying to do. Apologies for the confusion – montag Mar 24 '15 at 21:26

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.