假设在我的文件系统中有以下say-hello.ps1
文件:
function SayHello()
{
return "Hello World!"
}
可以在命令行中这样调用(最终将作为Windows计划任务运行):
powershell -ExecutionPolicy unrestricted -command "& { c:\say-hello.ps1; SayHello }"
我为什么会得到以下结果?
SayHello : The term 'SayHello' 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.
At line:1 char:33
+ & { c:\say-hello.ps1; SayHello }
+ ~~~~~~~~
+ CategoryInfo : ObjectNotFound: (SayHello:String) [], CommandNot
FoundException
+ FullyQualifiedErrorId : CommandNotFoundException
–
,“
,”
。我建议再次尝试使用 ASCII 中的-
和"
来运行cmd
。 - jscott