Say I have an array of metadata items. The json data of such would look something like this:
[
{
"attributes": {
"created": "20/08/2020",
"valid": true,
"name": "foobar"
},
"id": 1
},
{
"attributes": {
"created": "22/08/2020",
"valid": true,
"name": "foobar"
},
"id": 3
}
]
What I'd like to do is find the metadata item in the array that has the newest created data and return the whole of the item metadata item (i.e. such that I still have access to the other fields of the metadata).
I was trying to do something like this:
$myArray | Sort-Object -Property attributes.created | Select-Object -Last 1
But this doesn't work as -Property only seems to be able to be used with properties one level deep only.
I guess I'm trying to get the Powershell equivalent of the C#
var itemIWant = myArray.OrderByDescending(o => o.attributes.created).First();
How can I achieve this?