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

时间:2022-09-28 00:32:09

I am writing a script to use multiple plink (PuTTY) sessions as a Windows version of clusterssh. I am stuck however because I want to open multiple Powershell windows from powershell. When I type the command for powershell, it opens a new session. This is similar to typing bash in bash. I want multiple physical windows opening.

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

I tried -windowstyle as well as the other args to no avail. I was wondering if there is a way you know of. I really appreciate your help. I looked and didn't find anything already here. Thanks for your time.

我试过-windowstyle以及其他args无济于事。我想知道你是否有办法知道。我非常感谢你的帮助。我看了,在这里找不到任何东西。谢谢你的时间。

4 个解决方案

#1


15  

This will do it:

这样做:

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

#2


102  

This will open a new window.

这将打开一个新窗口。

Either:

或者:

start-process powershell

Or:

要么:

start powershell

#3


8  

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

如果您尝试打开新窗口并启动新脚本:

start powershell {.\scriptInNewPSWindow.ps1}

#4


1  

This works for me:

这对我有用:

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

$ 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.

(反引号是必要的。这可以直接复制。)变量可以在“-file”参数中使用(例如在脚本开头设置一个以反映文件的位置)并且空格可以出现在变量中由于反击。

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

编辑使用两行解决方案(“$ argList”变量),因为PowerShell可能会破坏其他内容。

#1


15  

This will do it:

这样做:

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

#2


102  

This will open a new window.

这将打开一个新窗口。

Either:

或者:

start-process powershell

Or:

要么:

start powershell

#3


8  

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

如果您尝试打开新窗口并启动新脚本:

start powershell {.\scriptInNewPSWindow.ps1}

#4


1  

This works for me:

这对我有用:

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

$ 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.

(反引号是必要的。这可以直接复制。)变量可以在“-file”参数中使用(例如在脚本开头设置一个以反映文件的位置)并且空格可以出现在变量中由于反击。

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

编辑使用两行解决方案(“$ argList”变量),因为PowerShell可能会破坏其他内容。