PowerShell Genie

Objects versus text

Understand why a displayed table is only a view, and inspect the properties behind it.

Lesson 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Overview

A service table may show Status, Name and DisplayName. That does not mean each row is a string containing three columns. The command returns objects; PowerShell chooses a display after the pipeline finishes.

Compare Get-Service | Select-Object -First 1 with the same command followed by Get-Member. The first displays a service. The second describes the type and available members. Get-Member consumes the objects you give it and returns member descriptions; it does not pass the original service along.

The example selects Name and Status before calling Get-Member. You should therefore expect a selected object with those properties. To inspect the original service type, call Get-Member before projecting the properties.

Text still appears in PowerShell: file lines, a quoted string and many native command responses are text. Once you use Out-String, the result is a string representation. Keep the original objects for filtering and exporting instead of splitting their displayed columns.

See the objects move

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

Get-Service | Select-Object -First 1 Name, Status, StartType
  1. Stage 1Get-ServicePositional values or no named parameters
  2. Stage 2Select-Object-First

    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.

      What happens

      Run the example and find Name and Status in the member list. Remove the Select-Object stage and compare the members again. The difference comes from the projection, not from a service changing on the machine.

      Worth remembering

      Use property names to work with structured data. Use text parsing when the source actually returns text.

      Primary documentation

      Microsoft Learn: objects

      Try it

      Browser simulation · fictional data; no changes to your computer.

      Interactive simulation · fictional data

      Get-Member describes the selected Name and Status properties; it does not pass the original service object to the next command.

      Show reference output

      Sample output · fictional data, shaped like the real thing

      Name    MemberType
      ------  ----------
      Name    Property  
      Status  Property  

      FIRST REPORT · READ THE PROPERTIES

      Practise without copying

      Return the first service with exactly Name, Status and StartType. Before running, name the property that tells you how startup is configured.

      How the worked example fits together

      A report begins with properties, not spaces in a displayed table. The first fictional service is BITS. Selecting its three properties produces one structured record that the next command can still inspect.

      Get-Service | Select-Object -First 1 Name, Status, StartType

      StartType describes startup configuration; Status describes the current state. Neither proves application health.

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

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

      Practise this

      Choose two service properties

      Return only Name and Status for all services.

      Review the lesson

      Keep going

      Next: The pipeline
      Genie guideObjects versus text

      Understand why a displayed table is only a view, and inspect the properties behind it.