Firstly, I have one question. Have you heard about Automatic Variables in Powershell? It’s a long list of read-only variables stored in the Powershell session. That is to say that every Powershell user should know this. Today I show you 5 most popular Automatic Variables, which all Powershell beginners should know. Let’s start.

More details

The Powershell Automatic Variables are created and stored automatically in the Powershell session. This type of variables is read-only. Above all, I don’t recommend you trying to assign some value to these variables.

Powershell itself create and assign the specific variable and then you can use it. To clarify, I prepared for you gif with example.

Most popular Powershell Automatic Variables

$PSVersionTable

This variable contains information about your Powershell version.

PSVersionTable

$Profile

The Profile variable contains the path to your profile file. For example, in this file you can modify and customize your Powershell environment. To clarify, I wrote more in the post How to speed up your work with Powershell profile.

$_

The next variable is more difficult to explain. By definition, this variable contains the object taken from pipeline. In other words, pipeline connect segments of your Powershell commands and allow you to move the result object from the previous Powershell command to another one. For example, you can use items from an array and move it to the Foreach loop in one line using the pipeline.

$Error

The $Error variable contains a history of errors from the current Powershell session.

$True / $False

I’m sure that you know these variables. The represent TRUE and FALSE value.

$NULL

This is the next primary variable, which probably you know. It represents an empty value.

$MyInvocation

This Powershell automatic variable contains information about the current command like name, and parameters.

$PSScriptRoot

The next variable is available during the Powershell script is running. It contains the script directory path. It’s helpful in the scenario when you want to load some other files from the same directory where Powershell script is located.

$PSCommandPath

Similarly to the previous one variable, this Powershell automatic variable also gives you the path. However, it contains a full path to the script file.

$Pwd

One more variable which contains a path. This one contains information about directory path where you are in Powershell console.

$IsLinux / $IsWindows / $IsMacOS

In the last point in this post, I show you three Powershell automatic variables. If you want to determine in your Powershell script the operating system type, you can use these variables. It’s very helpful if your script is multi-platform and can be run in Windows, Linux, and MacOS.

Conclusion

In conclusion, Powershell gives us a lot of Powershell automatic variables. In my opinion, I mentioned the most popular and the most useful for Powershell beginners. However, all list of Powershell variables you can find here.

Which one of Powershell automatic variables you are using the most often? Please leave a comment below.

Get Access to Poshland Resources for FREE!!!

Signup now and receive an email once I publish new content.

I agree to have my personal information transfered to MailChimp ( more information )

I will never give away, trade or sell your email address. You can unsubscribe at any time.