tags:

views:

528

answers:

2

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 recieve the following error:

The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling o
f 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?

+3  A: 

Is your param($p) the first line in your script? If it's not, that can cause the Param error. Make sure your param($p) is the first line.

David Longnecker
This is most likely the problem but first non-commented line would be sufficient.
Keith Hill
+4  A: 

I've solved the problem. I apologize for my incomplete and inconsistent information. I've corrected the description of the problem to make it accurate. I thank you for your help though.

The source of the problem is that I was incorrectly using the Param keyword multiple times. The correct usage is to declare multiple parameters within a single Param declaration like the following:

Param($p, $d)

This usage is explained in the Windows Powershell Help article "about_Functions".

John Ingle