The Show-Command cmdlet has been introduced in PowerShell Version 3 and is very useful to help discovering and learning more about PowerShell cmdlets and their respective parameters (also built into the ISE as the Show-Command Add-on).:
#Discover commands by running Show-Command without parameters Show-Command #Run Show-Command for a specific cmdlet Show-Command Get-ChildItem
Show-Command can be also utilized for your own functions in order to provide your users with a simple GUI as it builds a graphical user interface for the provided function on the fly. Show-Command displays:
- A drop-down for parameters that use the ValidateSet option
- A check-box for switch parameters
- A text box for any other type of parameter
- An asterisk behind the parameter name in case the parameter is mandatory (the mandatory parameters are also enforced by disabling the run/copy buttons until the mandatory parameter is provided)
- Each parameter set is displayed on a separate tab
Below is an example showing the features mentioned above using the NoCommonParameter switch to hide those parameters and PassThru in combination with Invoke-Expression in order to run the function with the chosen parameters (I couldn’t get this working otherwise):
Limitations of this approach are:
- No enforcement for any other advanced function parameter option (e.g. ValidatePattern). The error message is displayed on the command prompt after clicking Run.
- No option to disable/change the built-in functionality (e.g. disable buttons at the bottom, change minimum height)
- No sophisticated options for specific parameter types (e.g. browse for files)
What are the GUI options you like to you use for your functions?
Photo Credit: Sun Spiral via Compfight cc