Setting the Windows Terminal Tab to vCenter Name with PowerShell

Quick one. Today, I was working on some PowerShell using one of my favorite new Windows tools, Windows Terminal.

I’ve written about it a bit in the recent past:

https://www.codyhosterman.com/2020/05/defaulting-windows-terminal-to-powershell-7-x-core/

I often will connect to multiple vCenters, but even more frequently will have multiple vCenters connected but in separate sessions or tabs:

Four tabs, four vCenters. And I never clicked on the one I meant to be cause they were all called PowerShell. In a fairly recent release, Windows terminal added the option to rename the tabs:

Which is cool, but I don’t want to have to type my vCenter name again–and what if I screw it up and label the wrong one!!? We script to remove the chance of that, right?

Well there is an operation where you can rename the title:

$Host.UI.RawUI.WindowTitle

Set that to a new name, but I noticed it really only renamed the window, not the tab itself. As it turns out, this will only rename the tab if a specific parameter is added to your profile. So first, click on the top dropdown then settings

Under your PowerShell profile you will see something like this:

add “tabTitle”: “PowerShell” below source (don’t forget to add a comma after the source line:

Save it. Now if you set that variable, your tab will rename!

To set it accurately:

Run:

$Host.UI.RawUI.WindowTitle = $Global:DefaultVIServer.name

And repeat!:

Ah much easier to manage.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.