PowerShell Genie

Select-Object

Use Select-Object to keep only chosen properties, take the first N objects, or expand one property into its values.

Command 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn — Select-Object

Syntax

1PS> Select-Object [[-Property] <object[]>] [-ExpandProperty <String>] [-Unique] [-First <Int32>] [-Last <Int32>] [-Skip <Int32>] [<CommonParameters>]
See the command anatomy

Inspect this authored example with fictional data in the bounded browser model. The numbered stages show how its objects change.

Get-Process | Select-Object Name,Id,CPU
  1. Stage 1Get-ProcessPositional values or no named parameters
  2. Stage 2Select-ObjectPositional values or no named parameters

    The object workshop

    Watch your command work.

    Change the command. Step through the pipeline. Inspect what survives.

    5 fictional services

    Browser simulation · fictional services · Ctrl+Enter to run

      Object properties

      Enable JavaScript to step through this example. The lessons and command reference remain available.

      Your task: return the stopped service, with exactly Name and Status.

      Try it

      Windows PowerShell

      PowerShell example · browser support is limited.

      Execution scope: The full example below requires PowerShell outside this browser. You can edit this runner to use the supported practice commands; unsupported syntax returns an explanation.

      Interactive simulation · fictional data

      Examples

      Select Name, Id, CPU

      1PS> Get-Process | Select-Object Name,Id,CPU
      Show reference output

      Illustrative output · values vary by environment

      Name     Id     CPU   
      -------  -----  ------
      chrome   9184   842.31
      notepad  3200   0.4   
      pwsh     11268  18.27 
      spoolsv  4400   1.4   
      MsMpEng  2600   950   

      Select first 10

      1PS> Get-Process | Select-Object -First 10 Name,Id
      Show reference output

      Illustrative output · values vary by environment

      Name     Id   
      -------  -----
      chrome   9184 
      notepad  3200 
      pwsh     11268
      spoolsv  4400 
      MsMpEng  2600 

      Select Name

      1PS> Get-Service | Select-Object Name,@{ Name = "IsStopped"; Expression = { $_.Status -eq "Stopped" } }
      Show reference output

      Illustrative output · values vary by environment

      Name      IsStopped
      ----      ---------
      BITS      False
      Dnscache  False
      EventLog  False
      Spooler   False
      W32Time   False
      WinRM     True
      wuauserv  False

      Parameters

      Parameter definitions:

      • -Property
      • -ExpandProperty
      • -Unique
      • -First
      • -Last
      • -Skip

      Select-Object on Microsoft Learn

      Practical use and troubleshooting

      Practical scenario: Use Select-Object when you need to keep only chosen properties, take the first N objects, or expand one property into its values. Start with one identified target and inspect the returned values before extending the operation to a list. Keep the identity in your report so you can trace each result back to the object or path that produced it.

      Common error and fix: A later filter failing to find a property can result from projecting too early. Keep the fields needed by subsequent stages and reserve the final projection for the reporting boundary. In an unattended script, capture this failure with its original error record and record which target failed. An empty result and an unsuccessful query must remain distinguishable in the final report.

      See also: Where-Object. Where-Object keeps matching input objects; Select-Object chooses properties or a subset of objects. Projection is different from testing whether an object satisfies a condition. Read the linked command before substituting it; similar names do not imply identical inputs or output.

      Select-Object reference on Microsoft Learn

      FIRST REPORT · CHOOSE REPORT COLUMNS

      Practise without copying

      Return all automatic-start services sorted by Name, with exactly Name, DisplayName and Status. Keep the startup property until the filter has run.

      How the worked example fits together

      Projection decides the report contract. Keep every property needed by a later filter until that filter finishes. For this handover, DisplayName helps people identify a service, while Name remains the stable command identifier.

      Get-Service | Where-Object StartType -eq 'Automatic' | Sort-Object Name | Select-Object Name, DisplayName, Status

      The report has a deliberate schema and a stable row order. StartType is needed for filtering but does not have to appear in the final report.

      Bounded browser simulation · fictional services · no computer or tenant access.

      Predict the result, write your pipeline, then run it.

      Put this command to work

      Write your first report

      Save Name and Status for all services to C:\Lab\report.csv without type information.

      Review the lesson

      Recap

      Select-Object Use Select-Object to keep only chosen properties, take the first N objects, or expand one property into its values.

      Next: Where-Object
      Genie guideSelect-Object

      Use Select-Object to keep only chosen properties, take the first N objects, or expand one property into its values. The console below is pre-loaded — run it, then change a value and run it again.