如何在新窗口中从.bat启动 PowerShell,并在不退出控制台的情况下运行 .ps1



我想要一个.bat文件

  • 在新窗口中打开 PowerShell 控制台
  • 并运行 .ps1 脚本
  • 并且不会退出和关闭 PowerShell 控制台。

我的批处理文件包含以下行:

start powershell.exe -Command "&'D:MyToolkitToolKit.ps1'"

但是,它会在运行脚本后关闭 PowerShell。

有什么建议吗?谢谢

start powershell -noexit -file "D:MyToolkitToolKit.ps1"

-Command更改为-File,因为这是您需要的

不仅对于这个问题的原始海报,而且对于可能在这里寻找答案的其他人,帮助系统非常有用,似乎经常被忽视。

使用命令/?PowerShell get-helpget-help -full命令都很有用。

您可能已经通过阅读要运行的命令的帮助来回答自己的问题,在这种情况下powershell

PowerShell[.exe] [-PSConsoleFile <file> | -Version <version>]
    [-NoLogo] [-NoExit] [-Sta] [-Mta] [-NoProfile] [-NonInteractive]
    [-InputFormat {Text | XML}] [-OutputFormat {Text | XML}]
    [-WindowStyle <style>] [-EncodedCommand <Base64EncodedCommand>]
    [-File <filePath> <args>] [-ExecutionPolicy <ExecutionPolicy>]
    [-Command { - | <script-block> [-args <arg-array>]
                  | <string> [<CommandParameters>] } ]
PowerShell[.exe] -Help | -? | /?
-NoExit
    Does not exit after running startup commands.
...
-File
    Runs the specified script in the local scope ("dot-sourced"), so that the
    functions and variables that the script creates are available in the
    current session. Enter the script file path and any parameters.
    File must be the last parameter in the command, because all characters
    typed after the File parameter name are interpreted
    as the script file path followed by the script parameters.

-noExit -- 运行启动命令后不退出。

-文件--。。。文件必须是命令中的最后一个参数...

最新更新