Am I doing something stupid here?
I indicate that the function takes a certain type of enumeration as an argument:
PS> add-type -AssemblyName System.ServiceProcess PS> function test([System.ServiceProcess.ServiceControllerStatus]$x) { Write-host $x $x.gettype() }
The type is most definitely in scope since I can access its instances (and I imported the assembly manually):
PS> [System.ServiceProcess.ServiceControllerStatus]::Stopped Stopped
Then, when I try to pass an instance of the specified enumeration to the function, it throws an error:
PS> test [System.ServiceProcess.ServiceControllerStatus]::Stopped test : Cannot process argument transformation on parameter 'x'. Cannot convert value "[System.ServiceProcess.ServiceControllerStatus]::Stopped" to type "System.ServiceProcess.ServiceControllerStatus". Error: "Unable to match the identifier name [System.ServiceProcess.ServiceControllerStatus]::Stopped to a valid enumerator name. Specify one of the following enumerator names and try again: Stopped, StartPending, StopPending, Running, ContinuePending, PausePending, Paused" At line:1 char:6 + test [System.ServiceProcess.ServiceControllerStatus]::Stopped + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidData: (:) [test], ParameterBindingArgumentTransformationException + FullyQualifiedErrorId : ParameterArgumentTransformationError,test
It is quite happy that imposes a rope:
PS> test 'Stopped' Stopped System.ServiceProcess.ServiceControllerStatus
What's happening?
source share