I'm studying powershell functions and its valid parameters. Although I do not understand that they are really useful.
I make a simple example.
get-choice function ([parameter (mandatory = $ true)] [string] [ValidateSet ('y', 'n')] $ option {return $ option} get-election K This function gives me this error:
get-option: Impressible qualifier l 'armamento soul parametro' preference 'l' armamento "k" Non-aperture al set valid according to "Y, N" Specification Valid Furnir ur Armeno inclusive so many nail sets Ed Egmore de Neuve il Comondo Riga in: 6 cars: 11+ receiving options & lt; & Lt; & Lt; & Lt; K + category Info: Invalid data: (:) (meet), parameter binding validity exception + Fully Qualified Errida: ParameterArchiveErrorization error, get-option If I do not specify a valid group of values So I can see them within my code:
function get-choice 2 ([parameter (mandatory = $ true)] [string] $ option) {if ($ option - Y 'and $ option-' n ') {write-host "yes and no you I have to choose between "return", choose option, 2-k and I'll get more friendly message: First of all I would like to know whether the error It is possible to customize the message I and
so I hope someone can explain why I should first prefer the approach. thank you in advanced.
Some reasons to use standard validation:
- Annotative code ; 4 lines of code compared to 1 line with very little (again
return statement)
> There may be some bugs in the custom code
PowerShell's VS may contain some custom verification messages (?) (Just dreaming)
... Check - Post @ Geek You will see how you can customize the error message. It's a little developer oriented, but it's worth reading.
Comments
Post a Comment