Reputation: 38180
If I run in Windows Terminal PowerShell tab:
start-process Powershell -Verb runas
It will create a new window. Is there a way to create a tab in Windows Terminal instead?
Upvotes: 4
Views: 1408
Reputation: 437100
You must use the Windows Terminal CLI, wt.exe
, as the target executable for Start-Process
, and pass it the PowerShell CLI (powershell.exe
for Windows PowerShell, pwsh.exe
for PowerShell (Core) 7+) as its argument; e.g., with powershell.exe
:
Start-Process -Verb RunAs wt.exe powershell.exe
Note that if PowerShell is used as your default Windows Terminal profile, you needn't specify an argument for wt.exe
at all.
If you have a Windows Terminal profile defined for PowerShell (which should be true by default for at least Windows PowerShell), you can request it by name or GUID, via the -p
option. A profile name must specified in full, with the exact case as defined, (otherwise it is ignored and the default profile is used); e.g.:
Start-Process -Verb RunAs wt.exe '-p "Windows PowerShell"'
Note:
The first elevated Windows Terminal process invariably opens in a new window.
If at least one such process already exists, you can request that additional elevated processes open as tabs in that window with -w 0
as the first option; e.g.:
Start-Process -Verb RunAs wt.exe '-w 0 -p "Windows PowerShell"'
Upvotes: 7