I have an Array of "xml-node" objects:
xml-node object:
node <---------- this object is the one that has 3 other attributes (see below)
path
pattern
Node:
filename
modification
type
Problem:
I want to sort this array of xml-nodes based on the "modification" attribute; how would I go about it?
I've tried:
$nodes | sort-object Node.modification
Use the property name only for sorting by the object's immediate properties.
$nodes | sort-object modification
You can also use a ScriptBlock to sort objects. So this would work as well:
$nodes | sort-object { $_.modification }
Obviously that is not very useful by itself, but if you want to sort the objects in some way other than simply the property, you can manipulate the properties inside the ScriptBlock.
For example to sort processes by the last chatacter in the process name.
get-process| sort-object { $_.name[-1] }
Edit:
To access a property's property:
$nodes | sort-object { $_.node.modification }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With