How to get the name of an object property in powershell?
32,724
Solution 1
try:
( $result | get-member)[-1]
Solution 2
You can also try this to get all of the property names
foreach ($property in $result.PSObject.Properties) { $property.Name }
Author by
starcodex
Updated on May 31, 2020Comments
-
starcodex almost 4 years
I know I can use get-member to get all the properties of an object but I'm going through a list of objects and I'm interested in the very last property whose name keeps changing. To automate my script, I'm trying to get the name of that last property but I'm not sure how.
Let's say I have:
$result | get-member Name MemberType Definition ---- ---------- ---------- something something something . . . myProperty NoteProperty System.Object[]
"myProperty" changes with every different $result.
So does anyone know how I can do this?
-
starcodex almost 11 yearsCould I possibly filter that to find out the unknown name of the last property?
-
AndrewRalon about 3 yearsI needed that! Thanks.