如何从OS命令行启动PowerShell脚本?

时间:2021-01-07 00:37:23

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脚本用于构建我的项目文件,我希望能够从我的文件管理器的命令行运行它(并且,可能,创建一个这个脚本的快捷方式,这样我就可以从我的桌面开始构建)任何方式去做这个?

2 个解决方案

#1


36  

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。当然,如果您的脚本需要在配置文件中加载某些内容,则不要使用此参数。否则,它可以加快脚本的执行速度。

#2


-9  

invoke-command -computername -scriptblock{param()} -ArgumentList

invoke-command -computername -scriptblock {param()} -ArgumentList

#1


36  

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。当然,如果您的脚本需要在配置文件中加载某些内容,则不要使用此参数。否则,它可以加快脚本的执行速度。

#2


-9  

invoke-command -computername -scriptblock{param()} -ArgumentList

invoke-command -computername -scriptblock {param()} -ArgumentList