Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell 2.0 and "The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program"

Tags:

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?

like image 876
John Ingle Avatar asked Aug 22 '09 04:08

John Ingle


People also ask

How do you declare a parameter in PowerShell?

The name of the parameter is preceded by a hyphen ( - ), which signals to PowerShell that the word following the hyphen is a parameter name. The parameter name and value can be separated by a space or a colon character. Some parameters do not require or accept a parameter value.

Is not recognized as the name of a cmdlet function PowerShell?

If that module is missing, corrupt, or got moved, it throws up the error, “the term is not recognized as the name of a cmdlet.” You can use “get-module” in PowerShell to see if the module is present and correct. It will show you what modules are loaded, and you can add or repair them depending on your needs.

How do you write a function in PowerShell?

A simple functionA function in PowerShell is declared with the function keyword followed by the function name and then an open and closing curly brace. The code that the function will execute is contained within those curly braces. The function shown is a simple example that returns the version of PowerShell.


1 Answers

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.

like image 120
David R. Longnecker Avatar answered Sep 20 '22 08:09

David R. Longnecker