Your inputs should be strings, then you can cast them correctly to the System.Version type:
[System.Version]$INSV="9.4.11"
[System.Version]$NWTV="11.2.5"
If ($INSV -lt $NWTV){
Write-Host "Perfrom rest of the work!"
}
Else {
Write-Host "Exit!"}
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi,
I have this below code to compare 2 version numbers. However It does not work as expected as v9.4.11 is taken as grater version number than v11.2.5. How can I achive comparing 2 version numbers? Thanks.
$INSV=9.4.11
$NWTV=11.2.5
If ([version]$INSV -lt [version]$NWTV){
Write-Host "Perfrom rest of the work!"
}
Else {
Write-Host "Exit!"}
Your inputs should be strings, then you can cast them correctly to the System.Version type:
[System.Version]$INSV="9.4.11"
[System.Version]$NWTV="11.2.5"
If ($INSV -lt $NWTV){
Write-Host "Perfrom rest of the work!"
}
Else {
Write-Host "Exit!"}
Use strings:
$INSV="9.4.11"
$NWTV="11.2.5"
If ([version]$INSV -lt [version]$NWTV){
Write-Host "Perfrom rest of the work!"
}
Else {
Write-Host "Exit!"
}