Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Book Image

Microsoft Exchange 2010 PowerShell Cookbook

Overview of this book

Table of Contents (22 chapters)
Microsoft Exchange 2010 PowerShell Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Commonly-used shell variables


PowerShell and the Exchange Management Shell provide several automatic variables. The following table provides a list of commonly-used automatic variables with a description for each one:

Variable Name

Description

$$

Contains the last token in the last command received.

$?

Contains the execution status of the last command.

$^

Contains the first token in the last command received.

$_

Contains the current object being processed within a pipeline.

$Args

Contains an array of undeclared arguments received by function, script, or script block.

$Error

Contains an array of error objects recorded in the current shell session. The latest error can be accessed using the zero index of the array, that is, $error[0].

$Exbin

References the full path to the Exchange Server\Bin directory. This variable is only present when starting the shell using the Exchange Management Shell shortcut on a machine with the Exchange tools installed.

$ExScripts

References the full path to the Exchange scripts directory. This variable is only present when starting the shell using the Exchange Management Shell shortcut on a machine with the Exchange tools installed.

$False

Provides a Boolean false value when used in commands and scripts.

$ForEach

Contains the enumerator inside a ForEach-Object loop.

$Home

Contains the full path to the user's home directory.

$Host

Contains an object that represents the current PowerShell host application.

$Input

Contains the enumerator for items passed to a function. The $Input variable can access the current object being processed within a pipeline.

$MaximumHistoryCount

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

$Null

Provides a NULL or empty value when used in commands and scripts.

$Profile

Contains the full path to the PowerShell profile for the current user and current host application.

$PSHome

Contains the full path to the installation directory of Windows PowerShell.

$Pwd

Contains the path to the current location.

$True

Provides a Boolean true value.

To view the variables currently defined in your shell session, run Get-Variable. You can also read more about PowerShell variables by running the Get-Help <TopicName> cmdlet on the following About topics:

  • about_Automatic_Variables

  • about_Environment_Variables

  • about_Preference_Variables

Note

The preceding topics only reference PowerShell specific variables, and not the shell variables that are specific to the Exchange Management Shell.