Compare Versions

by Mar 14, 2016

Ever wanted to compare software versions? If you do it like this, the result is off:

PS> '' -gt ''

Here, PowerShell does a string comparison. To get the correct result for version numbers, simply hint the type:

PS> [Version]'' -gt ''

The type needs to be defined for the left side only. PowerShell automatically converts the right side to the type of the left side if they are different.

Twitter This Tip! ReTweet this Tip!