# SenddKeys that uses an automatic variable to a new tab

**URL:** <https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006>\
**Category:** PowerShell Help\
**Created:** [November 10, 2024, 4:36am UTC](https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006 "2024-11-10T04:36:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajkelsey](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ajkelsey](https://forums.powershell.org/u/ajkelsey)\
**Post date:** [November 10, 2024, 4:36am UTC](https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006/1 "2024-11-10T04:36:00Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/2X/8/804c8a4cf5513805b78d6766adb717086f967f4b.png)

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:

```auto
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}")

```

---

<div class="post-metadata">

**Author:** ![matt-bloomfield](https://avatars.discourse-cdn.com/v4/letter/m/dec6dc/32.png) [@matt-bloomfield](https://forums.powershell.org/u/matt-bloomfield)\
**Post date:** [November 10, 2024, 10:08am UTC](https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006/2 "2024-11-10T10:08:17Z")

</div>

Hi, welcome to the forum 👋

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

```PowerShell
wt new-tab -p PowerShell --title MyNewWindow -noExit

```

---

<div class="post-metadata">

**Author:** ![ajkelsey](https://avatars.discourse-cdn.com/v4/letter/a/6de8d8/32.png) [@ajkelsey](https://forums.powershell.org/u/ajkelsey)\
**Post date:** [November 10, 2024, 5:14pm UTC](https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006/3 "2024-11-10T17:14:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [December 10, 2024, 5:15pm UTC](https://forums.powershell.org/t/senddkeys-that-uses-an-automatic-variable-to-a-new-tab/25006/4 "2024-12-10T17:15:24Z")

</div>

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