0

I am having an issue comparing IE versions with PowerShell.

I have the code below :

$CurVersion = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet Explorer').Version
    Write-Host "Current Version Of IE is $CurVersion"
IF ($CurVersion -gt "11.*")
            {
              "IE is up to date"    
            }
            ELSE
            {
              "IE needs to be updated"  
            }

However, this code doesn't work because $curversion is stored as a string. 9.11.9600.17914 IsPublic IsSerial Name BaseType -------- -------- ---- -------- True True String System.Object

I can remove part of the version number, convert that to int and compare it that way but I'm sure there must be a easier and simpler way.

Can someone help me with this?

Thanks in advance.

1 Answer 1

1
$CurVersion = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet Explorer').Version.Substring(2)

Adding .substring(2) should strip out the 9. and make your current script work to a point, The script will run into issues with IE9. If thats not a problem, crack on and stop reading.

For All Versions of IE you could use the code below. This will account for IE 9 version "9.0", IE 10 and 11 ("9.1") and anything else below 9 falls into the else at the end.

$CurVersion = (Get-ItemProperty 'HKLM:\SOFTWARE\Microsoft\Internet     Explorer').Version

IF ($CurVersion.StartsWith("9.0"))
{
$CurVersion2 = $CurVersion
}
ElseIF ($CurVersion.StartsWith("9.1"))
{
$CurVersion2 = $CurVersion.Substring(2)
}
Else
{
$CurVersion2 = $CurVersion
}   
Write-Host "Current Version Of IE is $CurVersion2"
IF ($CurVersion2 -gt "11.*")
        {
          "IE is up to date"    
        }
        ELSE
        {
          "IE needs to be updated"  
        }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.