Windows Terminal open new tab then launch a script

I use the new windows terminal with Powershell 7.x, my purpose is doing a script in my first tab, launch a new tab from this script and execute a new script into it. Currently I have ma function like this:

function test {
    Write-Output 'run my script'  
    wt -w 0 nt; # open new tab
    Write-Output 'run my other script' # => script launch in the current tab but not in new one
}

Any idea how to do that ?


Solution 1:

I would run a new PowerShell instance in the nt command, passing in your script for the second tab:

function runscripts {
    Write-Output "Here"
    wt -w 0 nt pwsh -NoExit -c {
        Write-Output "Here"
        Write-Output "There"
    }
}

Alternatively, if you just want the second tab to exit after viewing the output and hitting Enter:

function runscripts {
    Write-Output "Here"
    wt -w 0 nt pwsh -c {
        Write-Output "Here"
        Write-Output "There"
        Read-Host
    }
}