I run automation that installs a preset OS /w Drivers and configuration. I inherited the automation second hand and there's a lot to it. I have a system with hybrid graphics and it hands on verifying the display drivers. Now, I can walk over to the machine, open device manager, right click on one of the graphics devices, click uninstall (i do not delete the driver files) and then the automation continues. Once its done, the system restarts and both device drivers are back. I am wondering if there is a powershell command i can run to do the same task through automation?
what do you guys think!
You can do this using WMI instance:
Get-CimInstance -Query (@"
select * from win32_systemdriver where caption="{0}"
"@ -f "THING_TO_REMOVE") |
ForEach-Object {
$_.StopService()
$_.Delete()
}
foreach ($dev in (Get-PnpDevice | Where-Object {$_.Name -like "*Name of device to remove*"})) {
&"pnputil" /remove-device $dev.InstanceId; &"pnputil" /scan-devices
}
You can use this script in a UninstallAndRescan.ps1 file and execute it at startup using Task Scheduler if you need to execute it on every reboot as necessary.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With