如何让PowerShell在Windows终端中启动进程而不是新窗口?

4

如果我在 Windows 终端的 PowerShell 选项卡中运行以下命令:

start-process Powershell -Verb runas

这将创建一个新窗口。有没有办法在Windows Terminal中创建一个选项卡?

1个回答

7

您必须使用 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

请注意,如果将PowerShell用作您的默认Windows终端配置文件,则无需为 wt.exe 指定参数。
如果为PowerShell定义了Windows终端配置文件(至少对于Windows PowerShell),则可以通过名称或GUID通过 -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"'
    

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接