views:

89

answers:

2

In PowerShell if i have a list of strings containing versions "3.0.1.1","3.2.1.1" etc how can I Sort it the way System.Version would sort it in c#

+9  A: 
PS C:\> $ver="3.0.1.1","3.2.1.1"
PS C:\> $ver|%{[System.Version]$_}|sort

Major  Minor  Build  Revision
-----  -----  -----  --------
3      0      1      1
3      2      1      1
James Pogran
+1 my thoughts exactly...
Sung Meister
+3  A: 

Why not just convert it to a Version and sort that way?

$list = "3.0.1.1","3.2.1.1" 
$sorted = $list | %{ new-object System.Version ($_) } | sort
JaredPar
+1 You gonna have to practice to type faster probably ;)
Sung Meister
@Sung, I was slow in this case because I couldn't remember if | sort worked or not in PowerShell.
JaredPar