Category Archives: powershell

How to run a powershell script from console

首先,要确保running policy已经被修改了。默认的Restricted是不能运行的。 然后,如果script file不在path下面,需要指定全路径。 如果全路径中间有空格,需要加双引号,然后在最前面加&。例子如下: 1: & "c:\My Scripts\test.ps1" 详情请参考http://technet.microsoft.com/en-us/library/ee176949.aspx 补充: 以上的是在powershell的console下运行。如果要在普通的console下,或者在bat文件里面运行,需要用下面的命令: 1: powershell.exe c:\test.ps1 如果要看到输出,在powershell.exe后面加上-noexit。在上面那个链接里面说,如果路径有空格,可以用命令:powershell.exe &’c:\My Scripts\test.ps1’来运行,但是我在1.0里面没有成功。不知道2.0是不是可以。本来准备把powershell的脚本也放到dropbox里面,然后又可以用lanuchy来运行,目前还是没做到。
Also posted in productivity, software | Tagged | Leave a comment