Appendix C. PowerShell Automatic Variables

PowerShell defines and populates several variables automatically. These variables let you access information about the execution environment, PowerShell preferences, and more.

Table C-1 provides a listing of these automatic variables and their meanings.

Table C-1. Windows PowerShell automatic variables: Variables automatically used and set by Windows PowerShell

Variable

Meaning

$$

Last token of the last line received by the shell.

$?

Success/fail status of the last operation.

$^

First token of the last line received by the shell.

$_

Current pipeline object in a pipelined script block.

$args

Array of parameters passed to the script, function, or script block.

$confirmPreference

Preference that controls the level of impact that operations may have before requesting confirmation. Supports the values none, low, medium, high. A value of none disables confirmation messages.

$consoleFilename

Filename of the PowerShell console file that configured this session, if one was used.

$currentlyExecutingCommand

Currently executing command, when in a suspended prompt.

$debugPreference

Preference that controls how PowerShell should handle debug output written by a script or cmdlet. Supports the values SilentlyContinue, Continue, Inquire, and Stop.

$error

Array that holds the (terminating and nonterminating) errors generated in the shell.

$errorActionPreference

Preference that controls how PowerShell should handle error output written by a script or cmdlet. Supports the values

Get Windows PowerShell Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.