문제

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