Export (0) Print
Expand All

Shell variables

 

Applies to: Exchange Server 2013

Topic Last Modified: 2012-09-19

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:

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.

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 <root drive>:\Program Files\Microsoft\Exchange Server\V15\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.

 
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft