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
2009-04-02 18:57:48
+1 my thoughts exactly...
Sung Meister
2009-04-02 21:17:11
+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
2009-04-02 18:57:52
@Sung, I was slow in this case because I couldn't remember if | sort worked or not in PowerShell.
JaredPar
2009-04-03 00:08:19