Applies to: Exchange Server 2007 SP3, Exchange Server 2007 SP2, Exchange Server 2007 SP1, Exchange Server 2007
Topic Last Modified: 2006-08-17

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 Exchange Management 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 Exchange Management 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 Exchange Management 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

Table 1 lists several common automatic variables that are available for your use in the Exchange Management Shell.

Table 1   Common automatic variables

Automatic variable Description

$$

This variable contains the last token of the last line that is received by the Exchange Management Shell.

$?

This variable contains the success or fail status of the last operation.

$^

This variable contains the first token of the last line that is received by the Exchange Management Shell.

$_

This variable contains the current pipeline object that is used in script blocks, filters, and the Where statement.

$Error

This variable contains objects for which an error occurred when they are processed in a cmdlet.

$ExBin

This variable displays the full path of the Exchange Server\bin directory.

$ExScripts

This variable the full path of the Exchange scripts directory.

$ForEach

This variable refers to the enumerator in a ForEach loop.

$Home

This variable specifies the user’s root directory. It is the equivalent of %HomeDrive%%HomePath%.

$MaximumHistoryCount

This variable specifies the maximum number of entries that can be saved in the command history.

$PSHome

This variable specifies the directory where the Exchange Management Shell is installed.