如何从 Powershell 打开 Powershell 控制台窗口

我正在编写一个脚本,使用多个 plink (PuTTY)会话作为一个 Windows 版本的 Clusterssh。但是我被卡住了,因为我想从 Powershell 打开多个 Powershell 窗口。当我为 powershell 键入命令时,它会打开一个新的会话。这类似于在 bash 中键入 bash。打开多个实体窗口。

我试过了-窗口风格以及其他参数都没有用。我想知道你是否知道。我真的很感激你的帮助。我找过了,这里什么都没有。谢谢你抽出时间。

87816 次浏览

This will do it:

Invoke-Item C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe

This will open a new window.

Either:

start-process powershell

Or:

start powershell

if you are trying to open a new window and launch a new script:

start powershell {.\scriptInNewPSWindow.ps1}

This works for me:

$argList = "-file `"$Location\script.ps1`"" Start-Process powershell -argumentlist $argList

(The backticks are necessary. This can be copied outright.) Variables can be used in the "-file" parameter (such as one set at the beginning of the script to reflect the location of the file) and spaces can appear in the variable due to the backticks.

Edited to use a two-line solution (the "$argList" variable) because PowerShell can mangle things otherwise.

To start Powershell 6 from a PS console start pwsh might do the trick.
It starts in the same folder.

(I haven't delved into it but I guess PS6's pwsh.exe has to be in the path for it to work.)