Parameters provide a way to select options or provide input to a Windows PowerShell cmdlet. Some parameters are required and others are optional. If you enter a cmdlet without specifying its required parameters, Windows PowerShell prompts you to enter each required parameter. In the Windows PowerShell console you are prompted at the command line. In Windows PowerShell ISE a Parameter Prompt dialog box appears that provides a parallel functionality to the Windows PowerShell console interactive behavior. The dialog box cycles through the required parameters in sequence.
An important point of difference between the Windows PowerShell console experience and the Windows PowerShell ISE experience is the way a required array parameter is entered. The Parameter Prompt dialog box provides an OK button that functions the same way as the ENTER key. After you enter a value for the array parameter, you are prompted for the next value when you click OK or when you press ENTER. Clicking OK or pressing ENTER without entering a value signals the end of the array, the same way that pressing the ENTER key without entering a value signals the end of the array on the Windows PowerShell console. Note that the Cancel button on the Parameter Prompt dialog box cancels the entire command and not the last entered value in the array. In that sense, the Cancel button is the counterpart for CTRL+C on the Windows PowerShell console.
Use of the Parameter Prompt Dialog Box
- In the Command Pane, type
start-sleepand press ENTER. You will see the Parameter Prompt Dialog box appear. You will be prompted to give a value of the required parameter “Seconds”.
- Type a number in the text box, and click OK. The
start-sleep command runs for the specified number of seconds.
- Experiment by clicking Cancel instead of OK to
see that it cancels the command.
Use of the Parameter Prompt Dialog Box to Enter a Required Array Parameter
- In the Script Pane, open a new script file and type the
$var1 = 1 $var2 = 2 $var3 = 3 clear-variable
clear-variablecmdlet. However, Name is an array parameter, so you will be prompted with “Name”.
- In the Parameter text box, type “var1” and click OK or
press ENTER. You will be prompted for subsequent array values. When
prompted with “Name”, in the Parameter text box, type “var2” and
press ENTER. Click OK without entering a third value to mark
the end of the array.
- Next, in the Command Pane type the following lines to see the
values of the three variables. The values of var1 and var2 have
been cleared, but var3 still has its assigned value.
$var1 $var2 $var3
- Experiment by clicking Cancel instead of OK in
the Parameter Prompt dialog box to see that it cancels the