Warning this topic will bore most of you to tears. You have been warned!
Compare the behavior of these two cases, the first being a native posh cmdlet, the second being one of the vmware cmdlets:
ex. 1:
PS > Get-Command -commandType foo Get-Command : Cannot bind parameter 'CommandType'. Cannot convert value "foo" to type "System.Management.Automation.CommandTypes" due to invalid enumeration values. Speci fy one of the following enumeration values and try again. The possible enumeration va lues are "Alias, Function, Filter, Cmdlet, ExternalScript, Application, Script, All". At line:1 char:25 PS > [enum]::GetValues( | System.Management.Automation.CommandTypes | ) Alias Function Filter Cmdlet ExternalScript Application Script All
ex 2:
PS > New-OSCustomizationSpec -NamingScheme foo New-OSCustomizationSpec : Cannot validate argument "foo" because it does not belong t o the set "custom, fixed, prefix, vm". At line:1 char:38 PS > [enum]::GetValues( | VMware.VimAutomation.Client20.OSCustomizationSpecImpl | ) Exception calling "GetValues" with "1" argument(s): "Type provided must be an Enum. Parameter name: enumType" At line:1 char:18 + [enum]::GetValues( <<<< | VMware.VimAutomation.Client20.OSCustomizationSpecImpl |)
Things to note:
a. Microsoft provided the type name (System.Management.Automation.CommandTypes) in the error message. This is very helpful.
b. (we approach the part that's above my head) Microsoft structured the options to the CommandType parameter such that I could programmatically get them out. That's important to me.
Is there a workaround to get at these values? I don't know how big of a change here that I'm asking for, but it's one of those "would be nice" things to have.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)
You're right it will be better NamingScheme parameter to be enum type instead of string as it is now but still you can get valid values for this parameter because they are described in a ValidateSet parameter attribute.
You can check the Powershell team blog post for the way to get valid string values for a parameter. I've extracted a short script for the New-OSCustomizationSpec cmdlet
$cmd = Get-Command New-OSCustomizationSpec
$param = $cmd.ParameterSets[0].Parameters | where {$_.name -eq "NamingScheme"}
$param.Attributes[0].ValidValues
You're right it will be better NamingScheme parameter to be enum type instead of string as it is now but still you can get valid values for this parameter because they are described in a ValidateSet parameter attribute.
You can check the Powershell team blog post for the way to get valid string values for a parameter. I've extracted a short script for the New-OSCustomizationSpec cmdlet
$cmd = Get-Command New-OSCustomizationSpec
$param = $cmd.ParameterSets[0].Parameters | where {$_.name -eq "NamingScheme"}
$param.Attributes[0].ValidValues
Nice! That's perfect, thanks.
Author of the upcoming book: Managing VMware Infrastructure with PowerShell
Co-Host, PowerScripting Podcast (http://powerscripting.net)