Comparing Versions

When you compare version strings, PowerShell will use alphanumeric algorithms, which may lead to confusing results:

'3.4.22.12' -gt '22.1.4.34'
True

You should convert the strings to a System.Version type to compare version strings right. In fact, converting the left hand value is enough because PowerShell automatically converts the right hand value to the same type:

[System.Version] '3.4.22.12' -gt '22.1.4.34'
False

Twitter This Tip! ReTweet this Tip!


Posted Sep 01 2010, 08:00 AM by ps1
Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.