如果我在 Windows 终端的 PowerShell 选项卡中运行以下命令:
start-process Powershell -Verb runas
这将创建一个新窗口。有没有办法在Windows Terminal中创建一个选项卡?
如果我在 Windows 终端的 PowerShell 选项卡中运行以下命令:
start-process Powershell -Verb runas
这将创建一个新窗口。有没有办法在Windows Terminal中创建一个选项卡?
您必须使用 Windows 终端 CLI,wt.exe
,作为Start-Process
的目标可执行文件,并将 PowerShell CLI (powershell.exe
用于 Windows PowerShell,pwsh.exe
用于 PowerShell (Core) 7+) 作为其参数传递;例如,使用 powershell.exe
:
Start-Process -Verb RunAs wt.exe powershell.exe
wt.exe
指定参数。 -p
选项请求它。必须完整指定配置文件名称,并且大小写要与定义的完全相同(否则会忽略并使用默认配置文件);例如:Start-Process -Verb RunAs wt.exe '-p "Windows PowerShell"'
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"'