I have a case where I have to make a decision in script based on comparing versions Consider this example:
PS C:\>
[version]$SomeVersion='1.1.1'
[version]$OtherVersion='1.1.1.0'
PS C:\> $SomeVersion
Major Minor Build Revision
----- ----- ----- --------
1 1 1 -1
PS C:\> $OtherVersion
Major Minor Build Revision
----- ----- ----- --------
1 1 1 0
PS C:\>$SomeVersion -ge $OtherVersion
False
I would like to omit revision when comparing objects of type System.Version
I Can't find any sane way of doing that.
Is there any?
Note - I've tried doing :
PS C:\> ($scriptversion |select major,minor,build) -gt ($currentVersion|select major,minor,build)
Cannot compare "@{Major=1; Minor=1; Build=1}" to "@{Major=1; Minor=1;
Build=1}" because the objects are not the same type or the object "@{Major=1;
Minor=1; Build=1}" does not implement "IComparable".
At line:1 char:1
+ ($scriptversion |select major,minor,build) -gt ($currentVersion |sele ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ExtendedTypeSystemException
+ FullyQualifiedErrorId : PSObjectCompareTo
when I try to override revision number with 0 it says that it's read-only property... I have a workaround But I hoped to do it better with system.version