PowerShell -Command .\Foo.ps1
Foo.ps1
:Function Foo($directory) { echo $directory } if ($args.Length -eq 0) { echo "Usage: Foo <directory>" } else { Foo($args[0]) }
尽管
Foo.ps1
位于我调用 Powershell 的目录中,但这会导致:The term '.\Foo.ps1' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
- 编辑:由于
profile.ps1
包含PowerShell 正在更改目录而无法正常工作cd C:\
- 编辑:由于
然后我尝试调用它,指定脚本文件的完整路径,但无论我尝试什么,我都无法让它工作。我相信我必须引用路径,因为它包含空格,我需要将参数传递给脚本的文件名也是如此。
迄今为止最好的猜测:
PowerShell -Command "'C:\Dummy Directory 1\Foo.ps1' 'C:\Dummy Directory 2\File.txt'"
输出错误:
Unexpected token 'C:\Dummy Directory 2\File.txt' in expression or statement. At line:1 char:136.