PowerShell/Community-Blog

Update request - Can I Change the Command Window Title When Running a Script?

doctordns opened this issue · 14 comments

Update this older Scripting Guys post to the new blog

Summary of the update request

It's possible to change the window title with $host.UI.RawUI.WindowTitle

Here is a little code snippet which prompts the user for a new window title string. After the user has entered a string, this string will be used as the new window title.

"Testing the change of a PowerShell window title"
$Title = Read-Host -Prompt 'Please enter a new window title '
$Host.UI.RawUI.WindowTitle = $Title

This works for the console of both PowerShell and Windows PowerShell. It also works for the Windows PowerShell ISE. It does not work with Terminal or VS Code.

I tried it in Terminal, for me it works 🤔
ezgif-1-cef58fb07a83

What I was meaning was that there is not window title for terminal as a whole (C/F the ISE). Ther is, as you point out, a tab title. So the blog post should mention this too!

the best/recommended way to do this on all platforms is to use virtual terminal sequences
so like:

"Testing the change of a PowerShell window title"
$Title = Read-Host -Prompt 'Please enter a new window title '
write-host "$([char]27)]0;$Title`a" -nonewline

@LuanVSO Would you like to submit a PR to create this blog post?

not really comfortable writing a blog post as English is not my first language, but I'm happy to provide the code.

I have been out of the lop a bit over the past 6 months - lost my mother late last year and the fall out has been hard to deal with. I kind of lost my enthusiasm for most things. But after a brief trip to the home country, I feel much better. With that said...

Please consider having a go at this. If English is an issue: a) use google translate and b) leave the rest to me! I will happily do the editing for you to get your post out! Contact me privately and we can create the PR for you to issue.

@doctordns Is ghost-writing allowed? I could write the post and @LuanVSO could submit it under their name.

Ghostwriting goes against the spirit and intent of the blog. But you can both get credit for the post. Let me know if you submit a PR and want to credit both authors.

I have been absent here of late due to health reasons (and some personal issues that are harder to resolve), so apologies for the recent lack of input.

Sean makes a great point. If anyone wants to write a post, we can help. But it is their article. If two/three want to collaborate, well, I suppose, but I'd prefer each post have a single author. By all means you (SK) can help others to get the tone and contents right.

If it's still available I'd like to take a shot at this post. Of course giving credit to @LuanVSO