What Is a Cmdlet?
PowerShell commands are called cmdlets. They
are structured by a verb and noun concatenation in the form of
verb-noun. So in the cmdlet Get-Help
, Get
is the verb and Help
is the noun.
Tip
Use the Get-Help
cmdlet to view helpful information about working with cmdlets.
How Can I See the Possible Verbs for a Noun Command?
If you know the noun but are unsure of the possible verbs available, you can enter the noun with -?
to display the available verb-noun combinations. This also displays
additional nouns that are similar to the one you provided. For example,
SPSite -?
displays the available verbs not only for the SPSite
noun, but also for SPSiteAdministration
, SPSiteSubscription
, and other cmdlets available beginning with SPSite
.
What Is a Parameter?
Most cmdlets need values to perform the
desired actions. These values are provided to the cmdlet using
parameters in the following form:
-parametername <value>
What Is a Switch Parameter?
A switch parameter is a parameter used with a
cmdlet that does not take a value (or that is Boolean in nature and can
be set to a false
setting). The fact that the switch parameter is present “switches on” that option (true
setting) when executing the cmdlet.
Most of the time, switch parameters
are optional, but in some cases, you need to provide a switch. This
depends on the cmdlet being executed.
How Can I See the Possible Parameters for a Cmdlet?
Entering the cmdlet in the console with -?
as a parameter displays information about that cmdlet, along with the available parameters. Listing 1 shows an example.
Listing 1. Getting Information About a Cmdlet
Get-SPSite -?
Some cmdlets, such as Get-SPSite
, have different variations of parameters. These variations also are displayed within the information provided by the -?
parameter, as Figure 1 shows.
Figure 1. Using -? with a cmdlet provides various syntax information.
What Does F3 Do?
Pressing the F3 function key in the console
window displays the last-executed statement on the current prompt line.
Using the up and down arrows, you can page through the other previous
statements. This is useful for repeating or correcting previous command
entries. Use the left and right arrow keys to place the cursor within
the command text for corrections.
Tip
Pressing the Insert key on the keyboard allows you to overwrite text within the command text without pushing the text out.
What Does F7 Do?
This is probably the best-kept secret in
command consoles. Every time I show this to someone, they say they had
no idea it was available. If you have been entering several commands in a console screen, pressing the F7 function key displays a menu of the previously executed commands, as Figure 2 shows.
Figure 2. Pressing the F7 function key presents a command history menu.
Use the arrow keys to change the
selection in the menu. Pressing Enter executes the command selected.
Pressing F9 on the menu enables you to enter the command number you
want to re-execute but only places it on the line (the command is not
executed automatically).