Applies to: Exchange Server 2010 SP3, Exchange Server 2010 SP2
Topic Last Modified: 2009-02-16
Shell variables are a set of variables that are created and declared automatically by the Exchange Management Shell. The variables are maintained throughout your session as part of the system state and are available to all commands, scripts, and applications that run in that session.
The Shell supports two types of shell variables:
- Automatic variables provide a mechanism for passing information
to and from commands, scripts, and applications.
- Policy variables store information about the state of the
Shell.
You can use shell variables as you would use any other type of
variable. For example, the $PSHome
shell variable
stores the name of the directory where the Shell is installed, and
the $
_ shell variable stores the current pipeline
object. You can use these variables in a command to specify the
location of the file and to call a property of the
Get-ChildItem
object, as shown in the following
example:
Copy Code | |
---|---|
Get-ChildItem $PSHome | Sort {$_.Name} |
This command retrieves all items from the Shell installation
directory, and it uses the name property of the object that is
stored in the $
_ variable to sort the data when it is
displayed.
Common Shell Variables
The following table lists several common automatic variables that are available for your use in the Shell.
Common automatic variables
Automatic variable | Description |
---|---|
|
Contains the last token of the last line that is received by the Shell. |
|
Contains the success or fail status of the last operation. |
|
Contains the first token of the last line that is received by the Shell. |
|
Contains the current pipeline object that is used in script
blocks, filters, and the |
|
Contains objects for which an error occurred when they are processed in a cmdlet. |
|
Displays the full path of the Exchange Server\bin directory. This variable is only available if the Exchange management tools are installed. |
|
Displays the full path of the Exchange scripts directory. This variable is only available if the Exchange management tools are installed. |
|
Refers to the enumerator in a |
|
Specifies the user’s root directory. It is the equivalent of
|
|
Specifies the maximum number of entries that can be saved in the command history. |
|
Specifies the directory where the Shell is installed. |