Datasheet
Chapter 1: Getting Started with Windows PowerShell
13
Optional and Required Parameters
Cmdlets may have some parameters that are not required to be used each time the cmdlet is run and are
considered optional. You will find that most cmdlets have at least some optional parameters, especially
cmdlets that modify items, because not all properties of an item require changing at the same time. This
allows you to use only the optional parameters necessary to make the desired changes while leaving out
all other optional parameters.
Then there are other parameters that must always be used when the cmdlet is run. You will find that
most cmdlets that take an action such as creating, modifying, or removing items have at minimum one
required parameter to identify the items on which to take action. If any required parameters are left out
when running a cmdlet, Windows PowerShell prompts the user to enter an input value for each of the
missing required parameters.
The
Identity parameter is one of the most common required parameters, typically used by cmdlets
that need as input the name of the object on which to take some action. For example, the
Set-User
cmdlet modifies attributes on an existing user account in the Active Directory directory service.
The
Identity parameter is required when using Set-User and is used to identify the user account
on which the changes are to be made.
In Figure 1 - 8 , the
Set-User cmdlet is being used to set the Department attribute, but the Identity
parameter was not used to name the target user so the shell prompts the operator for the missing value.
Figure 1-8
Positional and Named Parameters
Another parameter characteristic to consider is whether a parameter is positional or named. A positional
parameter can be used without actually entering the parameter name, as long as the input value is in the
position where the parameter name would normally have been used. Positional parameters are
designated with a number, starting with position 1, then position 2, and so on. Using positional
parameters effectively can be a real time - saving practice.
c01.indd 13c01.indd 13 12/17/07 3:19:26 PM12/17/07 3:19:26 PM