1

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

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

yes that does work. I am not aware of that limitation about interactive prompts

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.