Question

how can I get the object with smaller name size from an array?

$a

Name Value
---- -----
name A
name AAAA
name BB
name AAAAAA

$a | get-smaller -property "name" ==> should return the object with name = A

thanks

Was it helpful?

Solution

$a | sort { $_.value.length }  | select -expand value -first 1

OTHER TIPS

To sort file input.txt by lines length and put the result to output.txt:

Get-Content -Path input.txt | sort { $_.length } > output.txt
  1. Result is not ASCII/case-sensitive sorted
  2. There might be problem with different encodings - lines are omitted
  3. Result is normally UCS-2 Little Endian
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top