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:

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 Where statement.

$Error

Contains objects for which an error occurred when they are processed in a cmdlet.

$ExBin

Displays the full path of the Exchange Server\bin directory. This variable is only available if the Exchange management tools are installed.

$ExScripts

Displays the full path of the Exchange scripts directory. This variable is only available if the Exchange management tools are installed.

$ForEach

Refers to the enumerator in a ForEach loop.

$Home

Specifies the user’s root directory. It is the equivalent of %HomeDrive%%HomePath%.

$MaximumHistoryCount

Specifies the maximum number of entries that can be saved in the command history.

$PSHome

Specifies the directory where the Shell is installed.