SenddKeys that uses an automatic variable to a new tab

The short story is that I am writing a script that will open new tabs in Windows Terminal. I would like to rename each tab using this command: $wshell.SendKeys("$Host.UI.RawUI.WindowTitle = 'test'{ENTER}"). However, I receive the error below.

Running $Host.UI.RawUI.WindowTitle = 'test'{ENTER} directly in a PowerShell does work. It is when I am passing it to a new PowerShell that I am having this issue. Is it possible for me to rename this new tab using a PowerShell script?

The complete code block:

wt new-tab -p PowerShell -noExit
Start-Sleep -s 0.5s
$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('PowerShell')
Start-Sleep -s 0.5
$wshell.SendKeys("$Host.UI.RawUI.WindowTitle = 'test'{ENTER}")

Hi, welcome to the forum :wave:

Why not just specify the title when you open the tab?

wt new-tab -p PowerShell --title MyNewWindow -noExit
2 Likes

Because I didn’t realize I could do that. Thanks, Matt. :grin:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.