how to do "If driver version is lower than x number" run c:\abc.exe

Hi Guys

Can someone please help me for the below issue:

I need to install a network driver is the version is lower than the latest.

I was doing this via reg location, but it seems the key is in different places on same models, I assume it’s how windows decides/ feels lol

So I know how to get the driver version:

Get-WmiObject Win32_PnPSignedDriver| select DeviceName, DriverVersion, Manufacturer | where {$_.DeviceName -like “Realtek RTL8822BE 802.11ac PCIe Adapter”}

Can someone please help with what I need to do for if it is lower than eg 10.2.10 then run c:\abc.exe /s

Thanks in advance

You can get the driver version more efficiently by using a WMI Filter. At the moment, you’re getting all of the drivers and then filtering them with Where-Object.

[System.Version]$installedVersion = Get-WmiObject Win32_PnPSignedDriver -Filter "DeviceName = 'Realtek RTL8822BE 802.11ac PCIe Adapter'" | Select-Object -ExpandProperty DriverVersion

By declaring the [System.Version] type you get objects that are easy to compare

PS E:\Temp> Write-Output $driverVersion

Major  Minor  Build  Revision
-----  -----  -----  --------
10     0      19041  1

So then it’s just a case of doing the comparison:

$currentVersion = [System.Version]'10.2.10'

[System.Version]$installedVersion = Get-WmiObject Win32_PnPSignedDriver -Filter "DeviceName = 'Realtek RTL8822BE 802.11ac PCIe Adapter'" | Select-Object -ExpandProperty DriverVersion

if ($installedVersion -lt $currentVersion) {

    Start-Process c:\abc.exe -ArgumentList 's'

}

Thank you so much Matt.

That’s exactly what I was in need of.

Much appreciated.

Have a great day buddy!

Many thanks.

Sunny.