Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PowerShell disable and enable a driver

Sometimes after restart/coldboot I got a problem with my touchscreen driver in Win8, so I've to restart it manually by now.

So I want to write a script that starts after login, which will disable the driver and enables it again.

I actually found out to find the driver and that I can get a object list of the drivers via:

Get-WmiObject Win32_PnPSignedDriver| select devicename, driverversion | where {$_.devicename -like "I2C*"}

But adding "| Disable-Device" to the end of the line will not work.

Can anyone tell me how I have to write the command correctly and start the script like an batch file?

like image 939
pewpewPenguin Avatar asked Dec 22 '14 08:12

pewpewPenguin


People also ask

How do I disable a driver in PowerShell?

To enable disable a device, simply pipe the output of Get-PnpDevice to Disable-PnpDevice or Enable-PnpDevice. Please be sure your Get-PnpDevice command is targeting the correct device before piping to avoid accidentally disabling devices you'd rather keep enabled!

Can I disable and enable driver?

Open Start. Search for Device Manager and click the top result to open the app. Expand the branch with the driver you want to enable. Right-click the device and select the Enable device option.

Can you disable drivers?

Step 1: Open Windows Device Manager on your computer and expand the section of drivers you want to disable. Step 2: Right-click on the device driver and select “Disable device” from the context menu. Step 3: When there is a pop-up saying “Disabling this device will cause it to stop functioning.

How do I disable a device in Device Manager using PowerShell?

Thankfully Powershell makes it easy to get, enable and disable devices in Device Manager using Get-PnpDevice, Enable-PnpDevice and Disable-PnpDevice To enable disable a device, simply pipe the output of Get-PnpDevice to Disable-PnpDevice or Enable-PnpDevice.

Is there a way to disable out-of-box drivers using PowerShell?

Yes I am trying to use powershell to disable any unneeded drivers in MDT out-of-box drivers befored they are deployed. I have found a script that pulls a list of superseded drivers, but it only list them. I was hoping to add to it to disable them so I do not have to manually do it to test.

How do I disable a PNP device in PowerShell?

Disables a PnP device. The Disable-PnpDevice cmdlet disables a Plug and Play (PnP) device. You must use an Administrator account to disable a device. This command disables a device that has the specified instance ID. Runs the cmdlet as a background job.

How do I restart the graphics driver using PowerShell?

The simplest way to restart the graphics driver is mentioned in this Question: PowerShell disable and enable a driver But I cant use it because it needs admin privileges on executing. The Second and better approach is to use the win + ctrl + shift + b Hotkey which doesnt need admin rights.


2 Answers

at least with Windows 10 it is a lot easier:

$d = Get-PnpDevice| where {$_.friendlyname -like "I2Cwhatever*"}
$d  | Disable-PnpDevice -Confirm:$false
$d  | Enable-PnpDevice -Confirm:$false
like image 110
Falco Alexander Avatar answered Sep 18 '22 14:09

Falco Alexander


Assuming you are using the Device Management cmdlets, I'd suggest using the Get-Device cmdlet provided in the same pack to pass along the pipeline.

After a quick look, I found that Disable-Device doesn't take either of DeviceName or DriverVersion from the pipeline - and won't recognise either as it's only identifying parameter (-TargetDevice).

The technet page suggests this, to disable a device:

$deviceName = Read-Host -Prompt 'Please enter the Name of the Device to Disable'; Get-Device | Where-Object -Property Name -Like $deviceName | Disable-Device

You could simply use something like this, assuming your devicename is similar using the Get-Device cmdlet:

Get-Device | where {$_.name -like "I2C*"} | Disable-Device
like image 28
James Ruskin Avatar answered Sep 19 '22 14:09

James Ruskin