Hi, I’m Damian Garbus and today I tell you My way to understand Powershell variable for everyone. If you want to learn PowerShell, variable is the one of the basic things what you have to understand. What is this variable at all? Can be compare to something realistic? I think it can be 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 definition which can be found in some library. I write my own definition which I think will help you to understand what it is. Variable is some an abstract thing to which you can add some information. It can be one word or all tables of word. You can remove part of information but also you can add more. Also, variable can be empty (in technical word variable is equal null).
How to write variable (in more professional word – declare variable)
Let’s not waste your time, and run Powershell console. Powershell variable name format is “$MyVariable”. To insert something to variable you have to use equal sign “=” and type that we want to insert.
Now it’s time to use variable
When you have declared 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 add bad format. Let’s check how to do some operation on variable in PowerShell console.
Summary – 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 us 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 comment.
Maybe you have better way to understand PowerShell Variable, so please write in comments.