PowerShell script issue operators

前端 未结 1 1882
Happy的楠姐
Happy的楠姐 2021-01-21 10:18

I am attempting to use PowerShell to detect Intel NIC drivers, prior to deploying the updated drivers. I changed my script a bit to troubleshoot, to make sure I am capturing th

1条回答
  •  后悔当初
    2021-01-21 11:20

    String comparisons don't know anything about the inner structure of your version strings. Cast the strings to Version objects and you'll be able to do proper comparisons. Note that you need to expand the DriverVersion property for the conversion to work.

    [Version]$DeployVersion = "12.15.31.0"
    ...
    [Version]$CurrentlyInstalledDriverVersion = Get-WmiObject Win32_PnPSignedDriver |
        Where-Object {
            $_.deviceclass -match "NET" -and
            $_.devicename -like "*$INTELNICMODEL*" -and
            $_.driverversion
        } | Select -Expand driverversion
    

    0 讨论(0)
提交回复
热议问题