Chapter 15. Variables: a place to store your stuff

 

I’ve already mentioned that PowerShell contains a scripting language, and in a few more chapters we’re going to start playing with it. Once you start scripting, however, you tend to start needing variables, so we’ll get those out of the way in this chapter. Variables can be used in a lot of places other than long, complex scripts, so I’ll also show you some practical ways in which you can utilize them.

15.1. Introduction to variables

A simple way to think of a variable is as a box in the computer’s memory that has a name. You can put whatever you want into the box: a single computer name, a collection of services, an XML document, or whatever you like. You access the box by using its name, and when accessing it you can either put things in it, add things to it, or retrieve things from it (when you do so, those things actually stay in the box, so that you can retrieve them over and over).

15.2. Storing values in variables

15.3. Fun tricks with quotes

15.4. Storing lots of objects in a variable

15.5. Declaring a variable’s type

15.6. Commands for working with variables

15.7. Variable best practices

15.8. Common points of confusion

15.9. Lab

15.10. Ideas for on your own