开发者

Custom PowerShell Cmdlet does not accept Variables

开发者 https://www.devze.com 2023-04-09 18:51 出处:网络
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 flo

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开发者_StackOverflow社区:

What is needed in my PS cmdlet to get it to accept my variables? Thanks


This should work just fine if you specify the parameter on the command line, i.e:

get-mycmdlet -MyProperty $r

I don't think that the interactive prompts accept variables.

0

精彩评论

暂无评论...
验证码 换一张
取 消