PowerShell can't use the matching enum type?
You are running into a small gotcha regarding parsing modes. You can put parens around the argument and it will work:
test ([System.ServiceProcess.ServiceControllerStatus]::Stopped)
Alternatively, conversions from string to enum happen naturally, so you could write:
test Stopped
Here are a couple good links that discuss parsing modes:
- About Parsing
- Effective PowerShell Item 10: Understanding PowerShell Parsing Modes
You can pass an enum value as a string but you don't pass the typename as part of the argument e.g. this works just fine:
PS> test Stopped
Stopped System.ServiceProcess.ServiceControllerStatus
That said, when I'm calling .NET methods I prefer to use the fully qualified enum value instead of a string. That's because .NET methods tend to have multiple overloads and those that take strings can confuse PowerShell when to comes to picking the right overload.