Sort-object - Powershell

Hey

Is it possible to use "sort-object" based on result from a function?

$arr | sort-object function

Mike
LVL 1
mikeydkAsked:
Who is Participating?
 
oBdACommented:
If I understand you correctly, then yes, that should be possible. In case you're familiar with the "calculated properties" in Select-Object: it's similar with Sort-Object.
You can pass the Property argument not only object properties, but hash tables as well, with the expression you want to use for sorting.
This, for example, sorts the string array by their lengths:
'AAAA', 'BB', 'C', 'DDD' | Sort-Object -Property @{expression={$_.Length}}

Open in new window

0
 
PberSolutions ArchitectCommented:
No comment has been added to this question in more than 21 days, so it is now classified as abandoned.

I have recommended this question be closed as follows:

Accept: oBdA (https:#a42404009)

If you feel this question should be closed differently, post an objection and the moderators will review all objections and close it as they feel fit. If no one objects, this question will be closed automatically the way described above.

Pber
Experts-Exchange Cleanup Volunteer
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.