0

So I have created 2 objects called $Row1 and $Row2 which are populated with values in the following manner

$Row1 | Add-Member -MemberType NoteProperty -Name Name -Value $name
$Row1 | Add-Member -MemberType NoteProperty -Name Age -Value $age

$Row2 | Add-Member -MemberType NoteProperty -Name Name -Value $name
$Row2 | Add-Member -MemberType NoteProperty -Name Age -Value $age

I'm now looking for a way to access only the age value with Get-Content.

1 Answers1

0

The answer for this is that it would be suffice with writing $Row1.(TheNotePropertyName you want to access)

eg.

$Row1.Age
$Row1.Name
$Row2.Name

This works both for PScustomobjects and Psobjects. The difference between these are found here.

  • 1
    Yes, on _accessing_ properties with `.`, the [member-access operator](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_Operators#member-access-operator-), PowerShell doesn't distinguish between type-native properties and `NoteProperty` properties added via PowerShell's [ETS](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_types.ps1xml). While there is no real difference between `[pscustomobject]` and `[psobject]`, the latter should really be considered an invisible helper type that is not to be used directly. – mklement0 Mar 10 '20 at 13:58