windows 如何从操作系统命令行启动 PowerShell 脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3324409/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to launch PowerShell script from the OS command line?
提问by skevar7
I have a PowerShell script for building my project files, and I'd like to have capability to run it from my file manager's command line (and, possibly, make a shortcut to this script so I can start build from my desktop)
Any way to do this?
我有一个用于构建我的项目文件的 PowerShell 脚本,并且我希望能够从我的文件管理器的命令行运行它(并且,可能,为此脚本创建一个快捷方式,以便我可以从我的桌面开始构建)
任何方式去做这个?
回答by Keith Hill
If you're on PowerShell 2.0 use:
如果您使用的是 PowerShell 2.0,请使用:
PowerShell.exe -File c:\users\john\myscript.ps1
If you're on 1.0 use:
如果您使用的是 1.0,请使用:
PowerShell -Command "& {c:\users\john\myscript.ps1}"
Depending on what you do/load in your profile script you may also want to specify -NoProfile
. Of course, if your script requires something that is loaded in your profile then don't use this parameter. Otherwise, it can speed up execution of your script a bit.
根据您在配置文件脚本中执行/加载的操作,您可能还需要指定-NoProfile
. 当然,如果您的脚本需要在您的配置文件中加载某些内容,则不要使用此参数。否则,它可以稍微加快脚本的执行速度。
回答by user7315505
invoke-command -computername -scriptblock{param()} -ArgumentList
调用命令 -computername -scriptblock{param()} -ArgumentList