Fileversion issue

Welcome Forums General PowerShell Q&A Fileversion issue

This topic contains 2 replies, has 3 voices, and was last updated by

js
 
Participant
3 months, 3 weeks ago.

  • Author
    Posts
  • #109169

    Participant
    Points: 0
    Rank: Member

    Hi, I'm trying to get this script sorted out but I'm having an issue.  No matter what I put for the fileversion to check for it always comes back as "Already Installed".  So if I change the '14.2.770.0' to another value it should come back as "Not Installed".  Any ideas?

     

    function CheckSepVersion
    {
    $computername = $env:COMPUTERNAME
    $OSArch = Get-WmiObject -Class win32_OperatingSystem -ComputerName $computername | select pscomputername, OSArchitecture
    if ($OSArch.OSArchitecture -eq "64-bit")
    {
    (Get-Item "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\smc.exe").VersionInfo.FileVersion

    }
    else
    {
    (Get-Item "C:\Program Files\Symantec\Symantec Endpoint Protection\smc.exe").VersionInfo.FileVersion

    }
    }

     

    if (CheckSepVersion -eq '14.2.770.0')
    {

    Write-Output "Already installed"

    }
    else
    {
    Write-Output "Not installed"

    }

     

  • #109190

    Participant
    Points: 261
    Helping Hand
    Rank: Contributor

    Let's tweak your code a little bit .... (BTW: you should put it between the tags, not after them! 😉 )

    function Get-SepVersion{
        $computername = $env:COMPUTERNAME
        $OSArch = Get-WmiObject -Class win32_OperatingSystem -ComputerName $computername | Select-Object -Property pscomputername, OSArchitecture
        if ($OSArch.OSArchitecture -eq "64-bit"){
            [version](Get-Item "C:\Program Files (x86)\Symantec\Symantec Endpoint Protection\smc.exe").VersionInfo.FileVersion
        }
        else {
            [version](Get-Item "C:\Program Files\Symantec\Symantec Endpoint Protection\smc.exe").VersionInfo.FileVersion
        }
    }
    
    if (Get-SepVersion -eq [version]'14.2.770.0') {
        Write-Output "Already installed"
    }
    else{
        Write-Output "Not installed"
    }

    If you like to compare versions you should cast the numbers as version objects.

  • #109193
    js

    Participant
    Points: 319
    Helping Hand
    Rank: Contributor

    Weird. 14 invisible characters at the end?? I guess you can trim it.

    PS C:\Users\js\Downloads> $a = (get-item VSCodeSetup-x64-1.19.2.exe).VersionInfo.fileversion
    PS C:\Users\js\Downloads> $a
    1.19.2
    PS C:\Users\js\Downloads> $a.GetType()
    
    IsPublic IsSerial Name                                     BaseType
    -------- -------- ----                                     --------
    True     True     String                                   System.Object
    
    
    PS C:\Users\js\Downloads> $a -eq '1.19.2'
    False
    PS C:\Users\js\Downloads> $a -match '1.19.2'
    True
    PS C:\Users\js\Downloads> $a -match '1.19.2$'
    False
    PS C:\Users\js\Downloads> $a -match '^1.19.2'
    True
    PS C:\Users\js\Downloads> $a | measure -Character
    
    Lines Words Characters Property
    ----- ----- ---------- --------
                        20
    
    PS C:\Users\js\Downloads> '1.19.2' | measure -Character
    
    Lines Words Characters Property
    ----- ----- ---------- --------
                         6
    
    PS C:\Users\js\Downloads> $a.trim() -eq '1.19.2'
    True
    
    PS C:\Users\js\Downloads> "...$a..."
    ...1.19.2              ...
    

The topic ‘Fileversion issue’ is closed to new replies.