Automatic Variables

The automatic variables are those variables that store the state of the Windows PowerShell. These variables will contain the information of a user and the system, default variables, runtime variables, and PowerShell settings. These variables can be created and maintained by Windows PowerShell.

Following is the list of automatic variables in PowerShell:

Variable nameDescription
$$This variable is used to represent the last token in the last line, which is received by the session.
$?This variable is used to represent the execution status of the last operation. If there is no error, it returns a True value otherwise False.
$^This variable is used to represent the first token in the last line, which is received by the session.
$_This variable acts as $PSItem. It contains the current object in the pipeline object.
$argsThis variable contains an array of values for undeclared parameters that are passed to a script, function, or script block.
$ConsoleFileNameThis variable is used to represent the path of the console file, which was recently used in the session.
$ErrorThis variable is used to contain an array of error objects which represent the most recent errors.
$EventThis variable is used to contain an object of PSEventArgs. PSEventArgs is an object used to represent an event that is being processed.
$EventSubscriberThis variable is used to contain an object of PSEventSubscriber. This object shows you an event subscriber of an event that is being processed.
$EventArgsThis variable is used to contain an object which represents the argument of the first event.
$falseThis variable is used to represent the False.
$foreachThis variable is used to contain the enumerators of a ForEach loop. This variable exists only while the ForEach loop is executing. And it will be deleted after completion of the loop.
$HomeThis variable is used to represent the full path of the user’s home directory.
$inputThis variable contains an enumerator that enumerates all the inputs passed to the function. It is only available to script blocks and functions.
$HostThis variable contains an object which shows a current host application for the Windows PowerShell.
$IsLinuxIf the current session is running on the Linux operating system, this variable contains a $True, otherwise $False.
$IsWindowsIf the current session is running on the Windows operating system, this variable contains a $True, otherwise $False.
$IsMacOSIf the current session is running on MacOS operating system, this variable contains a $True, otherwise $False.
$nullThis variable is used to represent a null or empty value. We can use it to represent an absent or undefined value in script and commands.
$PIDThis variable displays the PID of the process, which is hosting the session of the current PowerShell.
$PSItemThis variable acts as $_. It contains the current object in the pipeline object.
$PSHomeThis variable represents the full path of the installation directory for the Windows PowerShell.
$PSVersionTableThis variable is used to represent the read-only hash table, which displays the details about the version of PowerShell running in the current session.
$PWDThis variable is used to contain the path object, which shows you a full path of the current directory.
$ShellIdThis variable is used to represent the identifier of the current shell.