My way to understand Powershell variable for everyone.

Hi, I’m Damian Garbus and today I tell you My way to understand Powershell variable for everyone. If you want to learn PowerShell, the variable is one of the basic things what you have to understand. What is this variable at all? Can be compared to something realistic? I think it can be a box about which I wrote in The best reason for learning Powershell which no one will tell you. Yeah, PowerShell variable is like object with information which can be used in your scripts. Ok, so let’s check more details.  

What is PowerShell Variable? 

I don’t write a definition which can be found in some library. I write my own interpretation which in my opinion, will help you to understand what it is. The variable is some an abstract thing to which you can add some information. It can be one word or all table of the words. Also, the variable can be empty (in a technical word variable is equal null).

How to write variable (in a more professional word – declare a variable)  

Let’s not waste your time, and run Powershell console. Powershell variable name format is “$MyVariable”. To insert something to the variable you have to use the equal sign “=” and type that we want to insert.  

declare powershell variable

Now it’s time to use variable 

When you have declared the variable, we can use it and run some operation on it. Returning to the example with the box, If the box is empty we can put something in. When the box is not empty you can add something else or take something out. With PowerShell variable you can the same operations, but is one important information. If you have in the box (variable) numbers you can only add/remove numbers. You cannot add to number some text. In the future, I will explain why but now PowerShell tell you that you tried to add a bad format. Let’s check how to do some operation on the variable in PowerShell console. 

sue powershell variable

 

Conclusion – One of the ways to understand variable 

Finally, I hope this post help you understand what is PowerShell variable, how to declare PowerShell variable and how to use it. This is basics to do so now you can do some exercises with that. More details you can check on Microsoft Site. If you have some questions please write in the comment. 

Maybe you have a better way to understand PowerShell Variable, so please write in comments. 

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 MailerLite ( more information )

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