PowerShell 2.0 和“术语‘参数’不被识别为 cmdlet、函数、脚本文件或可运行程序的名称" [英] PowerShell 2.0 and "The term 'Param' is not recognized as the name of a cmdlet, function, script file, or operable program"

查看:156
本文介绍了PowerShell 2.0 和“术语‘参数’不被识别为 cmdlet、函数、脚本文件或可运行程序的名称"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行的是 Windows 7 RTM.默认安装 PowerShell 2.0.我正在使用出色的 Windows PowerShell ISE 来编辑我的脚本.我有以下脚本:

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

我将脚本保存为 SayItAgain.ps1.当我尝试像这样从交互式 shell 运行此脚本时:

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

./SayItAgain -p "Hello"

我收到以下错误:

术语Param"未被识别为 cmdlet、函数、脚本文件或可运行程序的名称.检查名称的拼写,如果包含路径,请验证路径是否正确,然后重试.

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?

推荐答案

我已经解决了这个问题.我已经更正了问题的描述,使其准确无误.

I've solved the problem. I've corrected the description of the problem to make it accurate.

问题的根源在于我多次错误地使用了Param 关键字.正确的用法是在单个 Param 声明中声明多个参数,如下所示:

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)

Windows PowerShell 帮助文章about_Functions"中解释了这种用法.

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

这篇关于PowerShell 2.0 和“术语‘参数’不被识别为 cmdlet、函数、脚本文件或可运行程序的名称"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆