Understanding PowerShell variables
A variable is like a box. We can put stuff in it. We can take that stuff out and put something else in it. The box may contain one thing, or it may contain many things. It may contain multiple things of the same type, for instance, 30 pairs of socks, or it can be like my kitchen drawer, and contain all sorts of different things, including string. We can organize the things it contains in different ways or not organize them, like my kitchen drawer. It may contain nothing at all.
A variable is really a label for a region of memory. That’s all it is – a name and an address in memory. When you tell PowerShell to use the contents of a variable, you’re telling it to go to that area of memory and use what it finds there. Using a label gives us two advantages; firstly, it saves a lot of typing, especially if the variable contains many objects. Secondly, it allows us to assign meaning, something that tells us, and other people reading...