Reputation: 18147
I am using following function to find out whether the release is Major ,Patch or Invalid.
Function Compare-Version {
[cmdletBinding()]
Param (
[version] $old,
[Version] $New
)
If ( $New -le $Old ) { return "Invalid" }
ElseIf ( $new.Major -eq $Old.Major -And $New.Minor -gt $Old.Minor ) { return "Patch" }
ElseIf ($new -gt $old) { return "Major" }
}
$TypeOfRelease = Compare-Version -Old "245.1" -New "246.1"
If ($TypeOfRelease -eq "Invalid" ) { "No operation"}
ElseIf ($TypeOfRelease -eq "Major") {"Change guid to support migration"}
Elseif ($TypeOfRelease -eq "Point") {"Just change the version don't upgrade GUID")
I hope enum can be of right choice rather than string. How to send enum as output result and compare it in powershell
Upvotes: 1
Views: 194
Reputation: 201652
In PowerShell v5 you will be able to declare enums directly e.g.:
enum VersionCompare { Invalid; Major; Patch }
In v3 you will need to use Add-Type e.g.:
PS> Add-Type -TypeDefinition 'public enum VersionCompare { Invalid, Major, Patch }'
PS> [VersionCompare]::Invalid
Invalid
Upvotes: 4