自定义 PowerShell Cmdlet 不接受变量
我有一个自定义 PowerShell cmdlet,它的输入属性之一具有以下属性。该属性是 float 类型的 get/set。我希望能够为该属性提供浮点值或变量。
[Parameter(
ValueFromPipeline=true,
ValueFromPipelineByPropertyName = true,
Mandatory = true)]
public float MyProperty
{
get { return _myProp; }
set { _myProp = value; }
}
像这样在我的脚本中声明和分配变量会导致以下错误。
[float]$r=0.05
--or--
$r=0.05
PS C:>get-mycmdlet
cmdlet Get-mycmdlet at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
myPropperty: $r
Cannot recognize "$r" as a System.Single due to a format error.
myProperty:
我的 PS cmdlet 需要什么才能让它接受我的变量? 谢谢
I have a custom PowerShell cmdlet that has the following attributes on one of the input properties. The property is a get/set of type float . I want to be able to supply this property with either a float value or a variable.
[Parameter(
ValueFromPipeline=true,
ValueFromPipelineByPropertyName = true,
Mandatory = true)]
public float MyProperty
{
get { return _myProp; }
set { _myProp = value; }
}
Declaring and assigning a variable in my script like this results in the following error.
[float]$r=0.05
--or--
$r=0.05
PS C:>get-mycmdlet
cmdlet Get-mycmdlet at command pipeline position 1
Supply values for the following parameters:
(Type !? for Help.)
myPropperty: $r
Cannot recognize "$r" as a System.Single due to a format error.
myProperty:
What is needed in my PS cmdlet to get it to accept my variables?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您在命令行上指定参数,这应该可以正常工作,即:
我不认为交互式提示接受变量。
This should work just fine if you specify the parameter on the command line, i.e:
I don't think that the interactive prompts accept variables.