7.2. Using the select-object Cmdlet

The select-object cmdlet lets you select specified properties of an object or set of objects. In addition, you can use the select-object cmdlet to select unique objects from an array of objects or to select a specified number of objects from the beginning or end of an array of objects. The select-object has the following parameters in addition to the common parameters listed in Chapter 6:

  • property — Specifies properties of interest

  • excludeProperty — Specifies properties to be excluded

  • expandProperty — Specifies a property to be selected and, if that property is an array, specifies that each value in the array should be selected

  • first — Specifies a number of values at the beginning of an array that are to be selected

  • last — Specifies a number of values at the end of an array that are to be selected

  • unique — Specifies that only unique values are to be selected

  • inputObject — Specifies an input object, if the input objects are not supplied by the preceding step of a pipeline

I demonstrate how you can use several of these parameters in the sections that follow.

7.2.1. Selecting Properties

You can use the select-object with the property parameter to select specified properties of an object. One use is to select properties for display. The property parameter is a positional parameter, so you can omit the parameter name if you prefer.

Suppose that you want to display the process name and handle count of running processes.

If you select processes using

Get Professional Windows® PowerShell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.