PowerShell 2.0 and “The term ‘Param’ is not recognized as the name of a cmdlet, function, script file, or operable program”

powershell

I am running Windows 7 RTM. PowerShell 2.0 is installed by default. I am using the excellent Windows PowerShell ISE to edit my scripts. I have the following script:

Param($p)
Param($d)
echo $p $d

I save the script as SayItAgain.ps1. When I try to run this script from the interactive shell like so:

./SayItAgain -p "Hello"

I receive the following error:

The term 'Param' 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 C:\users\cius\Code\powershell\SayItAgain.ps1:2 char:6
+ Param <<<< ($destination)
    + CategoryInfo          : ObjectNotFound: (Param:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Is this a known issue or am I simply using it wrong?

Best Answer

If your param($p) is not the first line in your script that can cause the Param error.

Make sure your param($p) is the first line.