0

I've written this code and does not have any error but the if part does not work another problem is that it does not consider the version number as a version so the is clause can cot work can someone guide me what the problem is

Windows client" | Select -first 1 )

$web.ParsedHtml.body.getElementsByClassName('vdi-links')[0].innerHTML -match "<LI>(\d{1,2}\.\d).*(https.*msi)"
$latestversion = Write-Host "$($Matches[1])".version
$FileName = write-host "Jabber $($Matches[1]).msi "
$downloadUrl= Write-Host "$($Matches[2])"

( $product= Get-WmiObject -Class Win32_Product | Where-Object name -Match 'Jabber' | Select-Object Name, Version )

      $rootPath = "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Cisco Jabber"

function download($thisLocalFile, $downloadurl){
    Invoke-WebRequest -Uri "$downloadurl" -TimeoutSec 3 -OutFile "$thisLocalFile"

}

function createFolder($newFolder){

    New-Item -Path $newFolder -ItemType "directory"

}


function checkParams(){
       
 [version] $installedversion 
 [version] $latestversion
    if( [version]$latestversion -lt [version]$installedversion){
        download ($thisLocalFile,$downloadUrl)
        createFolder ($newFolder)
        $newFolder = $rootPath + "\" + $latestversion

        $thisNewFile = $FileName

        $thisLocalFile = $rootPath + "\" + $latestversion + "\" + $thisNewFile

        $thisReturn = @($newFolder, $thisLocalFile, $sdownloadurl)
        Return $thisReturn
Write-Host "1"
    }
   else 
   {
          Write-Host "$latest version in already installed"

}
} ```
  • 2
    You have chosen a weird exerpt from your code, because we can't see you ever calling the functions you define.. The line `( $product= Get-WmiObject ...)` just sits there, nothing is captured. Then about your `if` not working: Variables `$installedversion` and `$latestversion` just output.. Shouldn't these be **parameters** to the function? As far as I can tell, they are now just new, local variables in the function and will both be `$null` – Theo Jun 05 '22 at 12:59
  • thank you for the help .I edit it ,now I've called the functions . about the if `$installedversion` has the content of version but `$latestversion` is empty (null),what should I do ??? – atefeh kasiri Jun 05 '22 at 19:36
  • You're still not showing how you call the checkParams function. We have absolutely no idea where these variables come from. Where are they defined? How should the function know of their existence? – Theo Jun 05 '22 at 19:55
  • Also, in PowerShell parameters to a function are **space** separated. By doing `download ($thisLocalFile,$downloadUrl)` you are actually sending one single parameter, which in this case is an array of two elements. – Theo Jun 06 '22 at 09:52

0 Answers0