【发布时间】:2020-01-16 15:21:45
【问题描述】:
当我创建函数时,我在家用笔记本电脑上遇到了奇怪的行为。参数不传递给函数。
例子:
function Get-Info {
param (
$input
)
$input | gm
}
使用此代码 (Get-Info -input 'test') 我收到错误:
gm : You must specify an object for the Get-Member cmdlet.
At line:5 char:14
+ $input | gm
+ ~~
+ CategoryInfo : CloseError: (:) [Get-Member], InvalidOperationException
+ FullyQualifiedErrorId : NoObjectInGetMember,Microsoft.PowerShell.Commands.GetMemberCommand
我也只是想用参数打印一个详细的语句,但我只得到一个空行。
为什么参数没有传入函数?
【问题讨论】:
-
$input变量有特殊含义。阅读Get-Help about_Automatic_Variables。 -
@JosefZ,感谢您的提示。我更改了参数名称,但收到相同的奇怪行为。
标签: function powershell parameter-passing