01 / GETTING STARTED · LESSON 04

Look beyond the text

Inspect an object and read one of its properties.

10 min · learn at your pace

Objects carry structure

A PowerShell result is often an object: a value with named properties and methods. The terminal shows a useful text view, but the underlying object carries more information.

Here is a small device object:

$device = [pscustomobject]@{
    Name = 'SRV-01'
    OS = 'Linux'
    MemoryGB = 16
}
$device

[pscustomobject] creates an object with the properties you provide. Each property has a name and a value.

Ask what is available

$device | Get-Member
$device.Name

Get-Member describes an object's properties and methods. The dot in $device.Name reads one property. A method is an action attached to an object; for example, 'hello'.ToUpper() returns an uppercase string.

Avoid parsing text from a table when a property already contains the value you need. Objects keep your scripts useful even when the terminal's presentation changes.

Try an example.ps1
$device = [pscustomobject]@{Name='SRV-01'; OS='Linux'; MemoryGB=16}
$device | Get-Member
YOUR TURN

Put it into practice.

Use the supplied $device object to output its MemoryGB property.

See an explained solution
One way to solve it.ps1
$device = [pscustomobject]@{Name='SRV-01'; OS='Linux'; MemoryGB=16}
$device.MemoryGB

$device.MemoryGB returns the numeric property, rather than a formatted description of the whole device.