2016-03-20 40 views
5

我想有一个.bat文件是如何在.Bat的新窗口中启动Powershell并在不退出控制台的情况下运行.ps1?

  • 打开新窗口
  • 并运行一个脚本名为.psl
  • 而且不退出并关闭PowerShell的
一个PowerShell控制台

我的bat文件有这样一行:

​​

但是它关闭鲍威运行脚本后运行rshell。

有没有建议吗? 感谢

+2

'启动PowerShell的-noexit -file “d:\ MyToolkit \ ToolKit.ps1”' – Avshalom

+1

谢谢!成功了!当我把它放到最后但是当我把它放在-Commandit工作之前它没有工作 – pencilCake

回答

8
start powershell -noexit -file "D:\MyToolkit\ToolKit.ps1" 

此外,

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

2

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

使用命令/?PowerShellget-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 - 运行启动命令后不退出。

- 文件 - ...文件必须在命令的最后一个参数...

相关问题