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).: [code language=”powershell”] #Discover commands by running Show-Command without parameters Show-Command #Run Show-Command for a specific cmdlet Show-Command Get-ChildItem [/code] 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): https://gist.github.com/c5ffad6e6e80411275f4
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? Update: I’ve added a follow-up post with a new function that removes the disadvantages mentioned above
Photo Credit: Sun Spiral via Compfight cc