Calling PowerShell function from command line

Viewed 17277

Given the following say-hello.ps1 file on my file system:

function SayHello()
{
    return "Hello World!"
}

called on the command line like so (it will eventually run as a Windows Scheduled Task):

powershell -ExecutionPolicy unrestricted -command "& { c:\say-hello.ps1; SayHello }"

Why am I getting the following result?

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
1 Answers
Related