Avatar of mikeydk
mikeydkFlag for Denmark asked on

Sort version numbers - Powershell


How do I sort version numbers: (in an array)

Avatar of undefined
Last Comment

8/22/2022 - Mon

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question

You may not even have to cast the value as a version
$data | sort

Open in new window


@aikimark - no that doesn't work because with string sorting you will get results like before

It depends on the source of the data in the array.  If they went in as versions, they shouldn't need casting.  If they came in as strings, then they will need to be cast as version data, either on input (population of the array) or in the Sort operation (as you've shown).
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck

It's a good point to make that it may be better to cast the data during population of the array.
I assumed that the data in the array is just strings from the way the question was asked, but that could be incorrect.