我想有一个.bat文件是如何在.Bat的新窗口中启动Powershell并在不退出控制台的情况下运行.ps1?
- 打开新窗口
- 并运行一个脚本名为.psl
- 而且不退出并关闭PowerShell的
我的bat文件有这样一行:
但是它关闭鲍威运行脚本后运行rshell。
有没有建议吗? 感谢
我想有一个.bat文件是如何在.Bat的新窗口中启动Powershell并在不退出控制台的情况下运行.ps1?
我的bat文件有这样一行:
但是它关闭鲍威运行脚本后运行rshell。
有没有建议吗? 感谢
start powershell -noexit -file "D:\MyToolkit\ToolKit.ps1"
此外,
更改-Command
到-File
,因为这是你所需要的
不只是这个问题的原始的海报,但对于其他人谁可能降落在这里寻找答案,帮助系统非常有用,似乎经常被忽视。
使用命令/?或PowerShell
get-help
和get-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 - 运行启动命令后不退出。
- 文件 - ...文件必须在命令的最后一个参数...
'启动PowerShell的-noexit -file “d:\ MyToolkit \ ToolKit.ps1”' – Avshalom
谢谢!成功了!当我把它放到最后但是当我把它放在-Commandit工作之前它没有工作 – pencilCake