PowerShell -Command .\Foo.ps1
Foo.ps1
:
Function Foo($directory)
{
echo $directory
}
if ($args.Length -eq 0)
{
echo "Usage: Foo <directory>"
}
else
{
Foo($args[0])
}
尽管我从调用Powershell的目录中找到了Foo.ps1
文件,但结果却是:
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
包含cd C:\
,PowerShell正在更改目录,因此未能正常工作。
然后我尝试调用指定脚本文件的完整路径,但无论我尝试什么,都无法让它工作。我认为我必须引用路径,因为它包含空格,就像我需要传递一个参数到脚本的文件名一样。
到目前为止最好的猜测:
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.