none
Compare int with String or (Compare three characters with four characters as decimal ) RRS feed

  • Question

  • Hello,

    Trying to get the bios information 
    If $Bios is 1.19.1 or 1.20.1 works fine
    But if $Bios is 1.8.1 or 1.9.0 (three characters compare with four characters) not getting the true value.

    $Bios = (Get-WmiObject -Class Win32_Bios).SMBIOSBIOSVersion
    $BiosVersion = "1.18.5"

    If ($Bios -lt $BiosVersion){
    eg:  update bios
    }

    Monday, July 9, 2018 10:09 AM

Answers

  • You cannot compare strings as numbers.

    You can convert to a version object.

    [version]$Bios = (Get-WmiObject -Class Win32_Bios).SMBIOSBIOSVersion
    [version]$BiosVersion = '1.18.5'
    if($Bios -lt $BiosVersion){


    \_(ツ)_/

    • Marked as answer by Khyber Matin Monday, July 9, 2018 11:36 AM
    Monday, July 9, 2018 10:18 AM