Update Specific device driver with powershell script - windows 10

I have multiple computers with different graphics cards (devices).

Here are the exact names:
NVIDIA Quadro M2000 NVIDIA Quadro K5000 NVIDIA Quadro K4200 NVIDIA Quadro K1200 NVIDIA Quadro FX 3800 NVIDIA Quadro M4000

which have old drivers that I want to update with a Powershell script. The newest drivers are in the Microsoft Catalog.

I want to update a specific driver in my case the video card driver with a powershell script.

How could I achieve this?

My first attempt:

Writing a script for multiple Cards which checks for already installed drivers and choses the first manually created inf files which is not included in the code yet and installs it but, I don’t need that when there is the possibility to update a specific device from the Catalog.

Here is a simple script to kinda get some information about the installed card:


clear
$KnownDevice =  NVIDIA Quadro M2000, "NVIDIA Quadro K5000", "NVIDIA Quadro K4200", "NVIDIA Quadro K1200", "NVIDIA Quadro FX 3800", "NVIDIA Quadro M4000"
$Driver1 = NVIDIA Quadro 2000,  NVIDIA Quadro 4000
$Driver2 = NVIDIA Quadro M2000,  NVIDIA Quadro K5000,"NVIDIA Quadro K4200", "NVIDIA Quadro K1200" , "NVIDIA Quadro M4000"
$Driver3 = "NVIDIA Quadro FX 3800"
$KnownDeviceVersion = "","","","","","",""
Write-Output "Searching for existing graphic card driver"
$graka = Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion, DeviceClass | where {$_.devicename -like "*Quadro*"}
if ($None -eq $graka){
    clear
    Write-Host ('ERROR: No graphics card driver found') -Fore Red
    Write-Host ('Info for Admin') -Fore Red
    $graka
    Write-Host ('Exiting Update') -Fore Red
    Start-Sleep -s 20
    Exit
}elseif(@($graka).length -gt 1 ){
    clear
    Write-Host('ERROR: Multiple Graphics card driver found. Call an Administrator for assistance')-Fore Red
    Write-Host('Info for Admin') -Fore Red
    $graka
    Write-Host "Exiting Update"
    Start-Sleep -s 20
    Exit
}
clear
Write-Host ('graphics card driver found') -Fore Green

Write-Host "Installed graphics card" $graka.devicename -Fore Green
Start-Sleep -s 5
clear
if (-Not ($KnownDevices.Contains($graka.devicename)))
{
    Write-Host('Installed Driver is not known - Call an Administrator for assistance') -Fore Red
    Write-Output "Info for Admin"
    Write-Output $graka
    Write-Output "Exiting Update"
    Start-Sleep -s 20
    Exit
}
clear
Write-Host('Installed Driver is known') -Fore Green
Write-Host('Checking Version...')
$graka
$graka.driverversion

 

i messed up the code format

[pre]

clear
$KnownDevice = “NVIDIA Quadro M2000”, “NVIDIA Quadro K5000”, “NVIDIA Quadro K4200”, “NVIDIA Quadro K1200”, “NVIDIA Quadro FX 3800”, “NVIDIA Quadro M4000”
$Driver1 = “NVIDIA Quadro 2000”, “NVIDIA Quadro 4000”
$Driver2 = “NVIDIA Quadro M2000”, “NVIDIA Quadro K5000”,“NVIDIA Quadro K4200”, “NVIDIA Quadro K1200” , “NVIDIA Quadro M4000”
$Driver3 = “NVIDIA Quadro FX 3800”
$KnownDeviceVersion = “”,"","","","","",""
Write-Output “Searching for existing graphic card driver”
$graka = Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion, DeviceClass | where {$_.devicename -like “Quadro”}
if ($None -eq $graka){
clear
Write-Host (‘ERROR: No graphics card driver found’) -Fore Red
Write-Host (‘Info for Admin’) -Fore Red
$graka
Write-Host (‘Exiting Update’) -Fore Red
Start-Sleep -s 20
Exit
}elseif(@($graka).length -gt 1 ){
clear
Write-Host(‘ERROR: Multiple Graphics card driver found. Call an Administrator for assistance’)-Fore Red
Write-Host(‘Info for Admin’) -Fore Red
$graka
Write-Host “Exiting Update”
Start-Sleep -s 20
Exit
}
clear
Write-Host (‘graphics card driver found’) -Fore Green

Write-Host “Installed graphics card” $graka.devicename -Fore Green
Start-Sleep -s 5
clear
if (-Not ($KnownDevices.Contains($graka.devicename)))
{
Write-Host(‘Installed Driver is not known - Call an Administrator for assistance’) -Fore Red
Write-Output “Info for Admin”
Write-Output $graka
Write-Output “Exiting Update”
Start-Sleep -s 20
Exit
}
clear
Write-Host(‘Installed Driver is known’) -Fore Green
Write-Host(‘Checking Version…’)
$graka
$graka.driverversion

[/pre]