Understanding Automatic Variables in Powershell

In PowerShell, one has the ability to call a variable just about any name in the book. The only exceptions to this are the variables that are already being managed by PSH, known as the Automatic Variables. These variables, without a doubt, will be the most repetitious objects you use in PSH next to functions. In this tutorial, you will learn about automatic variables in PowerShell.


If you have not already done so, click open Windows PowerShell ISE.
Step one.

In order to get a list of all the automatic variables, run the following command:


get-help about_automatic_variables

Copy and Try it

The list is actually quite long to show the output pane's contents, so we provide a chart of automatic variables for your convenience below:

Variable Name



Contains the last token in the last line received by the shell.


Contains the state of the last operation. True when successful, false otherwise.


Contains the first token in the last line received by the shell.


Contains the current object in the pipeline object.


Contains the current object in the pipeline object.


Stores the filename of the most recently reported console file.


Contains the current culture used by the OS.


An array of error objects representing the most recent errors.


Contains the EngineIntristics objects that represents the execution context of the Windows PowerShell host.


It contains the value False.


Contains the enumerator of a foreach-object loop.


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


Current host application for Windows PowerShell.


Contains the object currently in the pipeline in the Process block of a function.


Contains the exit code of the last Windows program executed.


Contains information about the current command. Useful for dynamically retrieving the filename and path of the current script.


Stores the current prompt level for nested prompts. This is a bit advanced, so you may want to run the get-help about_automatic_variables command for additional information


Contains NULL or empty value.


Contains the process identifier of the Windows PowerShell process.


Stores the full path to the Windows PowerShell user profile for the default shell.


Stores the full path to the installation of Windows PowerShell.


A hash table containing details about the version and build of the current Windows PowerShell console.


Stores the full path to the current directory.


Contains the identifier for the current shell.


Contains TRUE


Stores the name of the UI culture currently in use.

Step two.

There are quite a few variables created and managed upon execution of PowerShell. You can use TRUE and FALSE that actually contains the appropriate values rather than creating empty strings and as for values of the variables, you can query the values for the variables such as $PSVersionTable hash table and get all the information you need.

Remarks last but not least…

These variables are made to make our lives easier when scripting in PowerShell. Join us next time for additional Windows PowerShell tutorials! Till then…