Chapter 6. Objects: just data by another name

 

We’re going to do something a little different in this chapter. I find that PowerShell’s use of objects can be one of its most confusing elements, but at the same time it’s also one of the shell’s most critical concepts, affecting everything you do in the shell. I’ve tried different explanations over the years, and I’ve settled on a couple that each work well for distinctly different audiences. So, if you have some programming experience and are comfortable with the concept of objects, I want you to skip to section 6.2. If you don’t have a programming background, and haven’t programmed or scripted with objects before, start with section 6.1 and read straight through.

6.1. What are objects?

Stop for a second and run Get-Process in PowerShell. You should see a table with several columns, but those columns barely scratch the surface of the wealth of information available about processes. Each process also has a machine name, a main window handle, a maximum working set size, an exit code and time, processor affinity information, and a great deal more. In fact, there are more than 60 pieces of information associated with a process. Why does PowerShell show so few of them?

6.2. Why PowerShell uses objects

6.3. Discovering objects: Get-Member

6.4. Object attributes, or “properties”

6.5. Object actions, or “methods”

6.6. Sorting objects

6.7. Selecting the properties you want

6.8. Objects until the very end

6.9. Common points of confusion

6.10. Lab