Here, the $Test parameter must always be specified when calling the script or function. If it is not provided, PS will automatically prompt for the value. It will only accept one of the provided values as its input, and it will only accept string input (no weird GUIDs, XML documents, or random file references, etc.)
If any other input is provided, PS will display a red error and stop, allowing the user to call the function or script again with different parameters.
Trying to validate your own input should generally only take place in GUIs — for CLI, parameter validation is more than sufficient for just about anything you'll need.
Check out Get-Help about_Advanced_Parameters for more. 🙂
The topic ‘Try / Catch Help’ is closed to new replies.