Comparing Versions

by Sep 1, 2010

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

'' -gt ''

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] '' -gt ''

Twitter This Tip! ReTweet this Tip!