Sorting PowerShell versions

后端 未结 5 535
無奈伤痛
無奈伤痛 2020-12-10 12:34

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#?

5条回答
  •  Happy的楠姐
    2020-12-10 13:04

    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
    

提交回复
热议问题