Pergunta

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

Foi útil?

Solução

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

Outras dicas

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top