powershell - Sorting objects by multiple properties -


i'm trying use powershell sorting objects representing application verions

$versionsobjects = @{     major = 3     minor = 2     bugfix = 1 }, @{     major = 3     minor = 5     bugfix = 1 }, @{     major = 1     minor = 2     bugfix = 1 }, @{     major = 4     minor = 2     bugfix = 1 }  $sortedversions = ($versionsobjects | sort-object -property @{expression="major"; descending=$true}, @{expression="minor" ;descending=$true}, @{expression="bugfix"; descending=$true}) $sortedversions | %{echo ( "{0}.{1}.{2}" -f $_.major, $_.minor, $_.bugfix)} 

the output in same order input:

3.2.1 3.5.1 1.2.1 4.2.1 

but should

4.2.1 3.5.1 3.2.1 1.2.1 

what doing wrong?

if @ least in powershell v3.0 can this:

$versionsobjects = [ordered]@{     major = 3     minor = 2     bugfix = 1 }, [ordered]@{     major = 3     minor = 5     bugfix = 1 }, [ordered]@{     major = 1     minor = 2     bugfix = 1 }, [ordered]@{     major = 4     minor = 2     bugfix = 1 }  $versionsobjects | % { $_.values  -join '.' } | sort -descending {[version]$_ } 

or version:

$versionsobjects = @{     major = 3     minor = 2     bugfix = 1 }, @{     major = 3     minor = 5     bugfix = 1 }, @{     major = 1     minor = 2     bugfix = 1 }, @{     major = 4     minor = 2     bugfix = 1 }  $versionsobjects | % { $_.major,$_.minor,$_.bugfix  -join '.' } | sort -descending {[version]$_ } 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -