Chapter 3. Working with Objects in PowerShell
PowerShell is an object-oriented shell. Don't let this scare you because knowing how to work with PowerShell objects will make your life much easier. Objects in PowerShell have properties and methods, just as with objects in real life. For example, let's take a computer and try to see it as an object. It has properties such as the manufacturer, the number of CPUs, the amount of memory, and the computer type (for example, server, workstation, desktop, or laptop). The computer also has methods. For example, you can switch the computer on and off. Properties and methods together are called members in PowerShell. In Chapter 2, Learning Basic PowerCLI Concepts, you already saw the Get-Member
cmdlet that lists the properties and methods of a PowerShell object. In this chapter, you will learn all of the ins and outs of PowerShell objects. We will focus on the following topics:
- Using objects, properties, and methods
- Expanding variables and subexpressions in strings
- Using here-strings
- Using the pipeline
- Using the PowerShell object cmdlets
- Creating your own objects
- Using COM objects