PowerShell Automatic Variables

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 scriptblock.

$confirmPreference

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

$consoleFilename

Filename of the PowerShell console file that configured this session.

$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 non-terminating) errors generated in the shell.

$errorActionPreference

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

 

Supports the values SilentlyContinue, Continue, Inquire, and Stop.

$errorView

Preference that controls how PowerShell should output errors in the shell. Supports the values of Normal, and CategoryView (a more succinct and categorical view of the error.)

$executionContext

Means by which scripts can access the APIs typically used ...

Get Windows PowerShell Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.