PowerShell Studio: Improved Function Builder
- Details
- Written by David Corrales
- Last Updated: 22 April 2016
- Created: 27 August 2014
- Hits: 10864
In a previous article we covered the Function Builder. As of PowerShell Studio 2014 (v4.1.64), we improved parameter set support in the Function Builder.
As you can see, we altered the ordering of the fields to improve the over-all work flow of the tool.
Notice the question marks? If you hover or click on a question mark, a help message will popup explaining the respective field.
Parameter Sets
The Parameter Set field has been expanded to include an Output Type. Now you can specify an optional output type for each parameter set you define.
When a parameter set is defined, the Function Builder reacts accordingly. For example, the Parameter Set Filter is enabled and a Parameter Set column is added to the Parameters list.
(Before a Parameter Set is defined) | (After a Parameter Set is defined) |
Parameters
The biggest change to the Function Builder is the parameters section. The columns have been reordered to create a better flow when defining parameters.
The Parameter Set column has been changed from a single selection combo box, to a text field where multiple parameter sets can be defined. You can simply type in the name of the parameter set you wish to assign to the parameter:
You can also define a new parameter set within this field:
Or assign multiple parameter sets to a single parameter by using a comma separator.
The Pos column is an optional field where you can quickly define the parameter’s position attribute. By default, the parameter’s position is determined by the ordering of the parameters.
For parameters that are assigned to multiple parameter sets, you can define each position by using a comma separator. The position values should follow the same ordering as the parameter set assignments.
Of course, you can also assign the parameter’s position and parameter sets using the parameter’s editor dialog by clicking the edit button:
The Parameter Dialog’s Parameter Set section to allows you to assign multiple parameter sets:
Note that each parameter set has its own respective settings:
Parameter Set Filter
The Parameters section also includes a Parameter Set Filter.
The Parameter Set Filter allows you to either show all the parameters, only show the parameters that are not assigned to a parameter set, or only show parameters within a specific parameter set. Selecting a filter other than “Show All” allows you to work within that specific parameter set.
While in this mode, you can use the up and down menu buttons to move or swap the parameter positions.
For your convenience, the position field only shows the parameter’s position within the selected parameter set and does not list the other parameter set positions when a filter is applied.
By default (Show All filter) the up and down move button only changes the order in which the parameters are declared in the function.
Note: In the Show All mode, the Mandatory check box refers to the parameter’s first assigned parameter set.
When a parameter set is declared, the generated function will now include a switch statement to help you differentiate between the parameter sets:
switch ($PsCmdlet.ParameterSetName) { 'Name Set' { #TODO: Place script here break } 'Data Set' { #TODO: Place script here break } }
We hope that this will increase your work-flow and make the creation of advanced functions with multiple parameter sets easier then ever.
For licensed customers, use the forum associated with your product in our Product Support Forums for Registered Customers.
For users of trial versions, please post in our Former and Future Customers - Questions forum.