Chapter 7. Working with objects

 

This chapter covers

  • Using objects in PowerShell
  • Understanding object properties, methods, and events
  • Working with objects in the pipeline

When you work with Windows PowerShell for, say, 10 minutes or so, you start to suspect that it isn’t quite the standard command-line interface it appears to be. Many administrators, relying on previous experience with shells like Cmd.exe or Bash, struggle to use PowerShell efficiently and effectively. The reason for this is that—despite PowerShell doing its best to disguise this fact—it’s an object-oriented shell, which is a significant difference from the text-based shells of yesterday. Wrapping your head around this paradigm shift, you can see that PowerShell’s object-oriented nature is crucial to using the shell effectively.

Note

PowerShell is object oriented but that doesn’t mean you have to become a programmer to use it. You need to learn enough about objects to get the most of the shell—enough to use the tool effectively.

Although Don’s proverb “PowerShell hates text” isn’t exactly true, it does give you an idea how important it is to embrace object-based operations over text-based operations. This is directly analogous to using SQL for set-based operations on a database as opposed to using a sequential programming technique. You use the tool in the best way by using it correctly.

7.1. Introduction to objects

7.2. Members: properties, methods, and events

7.3. Sorting objects

7.4. Selecting objects

7.5. Filtering objects

7.6. Grouping objects

7.7. Measuring objects

7.8. Enumerating objects

7.9. Importing, exporting, and converting objects

7.10. Comparing objects

7.11. Summary