How to run a Powershell script from the command line and pass a directory as a parameter

前端 未结 6 1109
醉梦人生
醉梦人生 2020-12-24 04:40
PowerShell -Command .\\Foo.ps1
  • Foo.ps1:

    
    
            
6条回答
  •  半阙折子戏
    2020-12-24 05:14

    you are calling a script file not a command so you have to use -file eg :

    powershell -executionPolicy bypass -noexit -file "c:\temp\test.ps1" "c:\test with space"
    

    for PS V2

    powershell.exe -noexit &'c:\my scripts\test.ps1'
    

    (check bottom of this technet page http://technet.microsoft.com/en-us/library/ee176949.aspx )

提交回复
热议问题