Chapter 16. Variables, arrays, hash tables, and script blocks

 

This chapter covers

  • Variable names and types
  • Strict mode
  • Variable drives and cmdlets
  • Arrays
  • Hash tables
  • Script blocks

Variables are a big part of any programming language or operating system shell, and PowerShell is no exception. In this chapter, we’ll explain what they are and how to use them, and we’ll cover some advanced variable-like data structures such as arrays, hash tables, and script blocks.

16.1. Variables

Variables are quite simply a temporary storage area for data. If you have some piece of data you plan to use over and over again, it makes sense to store it in a variable rather than having to retrieve it from where it’s stored each time you need it. Or if you have a command that takes a long time to run and you want to try different things with the results, save the results to a variable so you don’t have to keep executing the same long-running expression.

16.2. Built-in variables and the Variable: drive

16.3. Variable commands

16.4. Arrays

16.5. Hash tables and ordered hash tables

16.6. Script blocks

16.7. Summary