Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the name of an object property in powershell?

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?

like image 560
starcodex Avatar asked May 30 '13 14:05

starcodex


2 Answers

You can also try this to get all of the property names

foreach ($property in $result.PSObject.Properties) { $property.Name  }
like image 199
Stanley De Boer Avatar answered Oct 15 '22 13:10

Stanley De Boer


try:

( $result | get-member)[-1]
like image 32
CB. Avatar answered Oct 15 '22 13:10

CB.