Javatpoint Logo
Javatpoint Logo

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 name Description
$$ 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.
$args This variable contains an array of values for undeclared parameters that are passed to a script, function, or script block.
$ConsoleFileName This variable is used to represent the path of the console file, which was recently used in the session.
$Error This variable is used to contain an array of error objects which represent the most recent errors.
$Event This variable is used to contain an object of PSEventArgs. PSEventArgs is an object used to represent an event that is being processed.
$EventSubscriber This variable is used to contain an object of PSEventSubscriber. This object shows you an event subscriber of an event that is being processed.
$EventArgs This variable is used to contain an object which represents the argument of the first event.
$false This variable is used to represent the False.
$foreach This 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.
$Home This variable is used to represent the full path of the user's home directory.
$input This variable contains an enumerator that enumerates all the inputs passed to the function. It is only available to script blocks and functions.
$Host This variable contains an object which shows a current host application for the Windows PowerShell.
$IsLinux If the current session is running on the Linux operating system, this variable contains a $True, otherwise $False.
$IsWindows If the current session is running on the Windows operating system, this variable contains a $True, otherwise $False.
$IsMacOS If the current session is running on MacOS operating system, this variable contains a $True, otherwise $False.
$null This 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.
$PID This variable displays the PID of the process, which is hosting the session of the current PowerShell.
$PSItem This variable acts as $_. It contains the current object in the pipeline object.
$PSHome This variable represents the full path of the installation directory for the Windows PowerShell.
$PSVersionTable This variable is used to represent the read-only hash table, which displays the details about the version of PowerShell running in the current session.
$PWD This variable is used to contain the path object, which shows you a full path of the current directory.
$ShellId This variable is used to represent the identifier of the current shell.





Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA