Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to change the title of the PowerShell window to the command line of the currently executing process inside it, just like CMD.EXE does.

Can I do this in PowerShell?

Is there some function like prompt which is called when I execute a command in PowerSHell?

share|improve this question

Do you want it for a small select number of executables? Or all exes?

One hack for a select number of executables would to do

function cmd
    $title = $host.UI.RawUI.WindowTitle
    $host.UI.RawUI.WindowTitle = 'cmd.exe ' + ($args -join " ")
    cmd.exe $args
    $host.UI.RawUI.WindowTitle = $title


Then just run cd c: cmd /c dir /s

And see the title change

And for all the commands

Get-Command -CommandType Application | where {$_.Name -match '.exe$'} | %{
$f = @'
    function {0}
        $title = $host.UI.RawUI.WindowTitle
        $host.UI.RawUI.WindowTitle = '{0} ' + ($args -join " ")
        {0}.exe $args
        $host.UI.RawUI.WindowTitle = $title
'@ -f ($_ -replace '.exe', '')
Invoke-Expression $f

And then try ping

Its hacky, YMMV

share|improve this answer
Wow, your second solution is truly evil :)) Unfortunately it doesn't work for programs not in PATH, like scripts in the current folder – Meh Oct 1 '10 at 22:48

This is definitely possible, though you do have to code for it yourself. This TechNet article describes how to change the Title line of the executing window.

share|improve this answer
That article only describes how to statically change the window title. I want a window title which adapts to what runs inside PowerShell. For example, when I type "PS> python.exe <ENTER>", I want the title bar to change to "Administrator: python.exe", just like in CMD.EXE. When python.exe terminates, the title bar should change back to "Administrator: Command Line" – Meh Jul 30 '10 at 19:13

Yes there is, this is my function for prompt, it put the last part of the actual path in the prompt. Also set the window title and when you runit as admin change the background and add a Admin: in the title.

function prompt{
$shortpath = split-path (Get-Location) -leaf;

$id = [System.Security.Principal.WindowsIdentity]::GetCurrent()
$p = New-Object System.Security.Principal.WindowsPrincipal($id)

   $host.UI.RawUI.WindowTitle = "ADMIN:$shortpath"
   if($FirstRun){$host.UI.RawUI.BackgroundColor = "Black"; cls; $global:FirstRun = 0;}
{$host.UI.RawUI.WindowTitle = $shortpath}

$(if (test-path variable:/PSDebugContext) 
   { '[DBG]: ' } 
else { '' }) + 'PS ' + $($shortpath) + $(if ($nestedpromptlevel -ge 1) { '>>' }) + '>         ';


Put that in your profile, remember that any profile is accesible directly with the profile variable: $profile.CurrentUserCurrentHost, $profile.CurrentuserAllhost ....etc.

share|improve this answer
Thanks, but this doesn't do what I want. It only puts the name of the current path in the title bar, not the name of the executable of the current running command. – Meh Aug 10 '10 at 7:37
One thing you could try is to query for child processes of the current host (via WMI query perhaps?). That should give you the exe being run, which you can put in the title. – scobi Dec 4 '13 at 16:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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