Datasheet
Chapter 1: Getting Started with Windows PowerShell
23
Using this procedure you can enter complex, mistake - free cmdlet names using a minimal number of
characters and Tab keystrokes. One major benefit of tab expansion is you don ’ t have to remember exact
cmdlet names as long as you can enter at least the verb name followed by a few letters of the noun name.
Tab expansion works for parameter names in the same manner. This works especially well when you
don ’ t know all the possible parameter names a cmdlet is using. To cycle through all the parameter names
type a hyphen and press the Tab key repeatedly. When the correct parameter name appears, continue
typing to enter the parameter value as applicable.
Be careful when using this procedure because Windows PowerShell does not validate the parameter
names entered on the command line until the command is parsed at run time. Using tab expansion it is
possible to inadvertently enter the same parameter name twice, causing the command to fail.
Using Cmdlet Aliases
Windows PowerShell allows you to refer to cmdlets using a shorter, simpler name called an alias. The
default installation of Windows PowerShell comes complete with several predefined alias names that
approximate a similar function in other command shells.
You may have already noticed that Windows PowerShell accepts
dir as a command to display items in
the current location. There is no real cmdlet called
dir , instead it is an alias for the underlying Windows
PowerShell cmdlet
Get-ChildItem . Several other familiar command names have been defined as alias
names for the matching Windows PowerShell command. To see a list of all alias definitions, run
Get-Alias .
Windows PowerShell also allows you to define your own alias definitions using the
New-Alias cmdlet.
The lifetime of alias definitions is linked to the lifetime of the current shell session. When the shell closes
the definition is lost. To learn more about aliases, type
Get-Help about_Alias .
Using Pipelines
As mentioned earlier in this chapter, the results of running a Windows PowerShell cmdlet is a collection
of one or more .NET objects. These objects have a structure that describes the properties (attributes) of
the objects and the states (current value) of these properties. This feature of Windows PowerShell makes
it possible to take the results of one cmdlet and pass it via pipeline as input to another cmdlet for further
processing. Using a pipeline to pass data from one cmdlet to another is known as composition .
The vertical pipeline operator (|) is used to instruct Windows PowerShell to pass the collected objects
from the command just prior to the pipeline to the next command. Commands can be constructed using
multiple pipelines to accomplish tasks too complex for a single cmdlet to accomplish alone.
Some cmdlets that use the
Get verb provide a way to limit the collection of objects based on a parameter
value that acts as a filter. The resulting collection can then be passed by pipeline to a cmdlet that uses the
Set verb to modify one or more properties on each object. For example, the Get-User cmdlet includes
the
OrganizationalUnit parameter.
Say your organization has implemented Organizational Units as a way to contain all users located in
the same geographical office. A need arises to change the fax number attribute for all user accounts in the
same office. Using the
Get-User cmdlet with the appropriate value for the OrganizationalUnit
parameter you can create a collection of user objects limited to the users in the office. By passing this
c01.indd 23c01.indd 23 12/17/07 3:19:29 PM12/17/07 3:19:29 PM