How to open Powershell Console Window from Powershell

拟墨画扇 提交于 2019-11-28 16:57:58

问题


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.

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.


回答1:


This will do it:

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



回答2:


This will open a new window.

Either:

start-process powershell

Or:

start powershell



回答3:


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

start powershell {.\scriptInNewPSWindow.ps1}



回答4:


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.




回答5:


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



来源:https://stackoverflow.com/questions/15667322/how-to-open-powershell-console-window-from-powershell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!