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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top