PowerShell disable and enable driver

Sometimes after rebooting / coldboot I had a problem with the touch screen driver in Win8, so I have to restart it manually.

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

I really found that I found a driver, and that I can get a list of driver objects through:

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 someone tell me how I need to write the command correctly and run the script as a batch file?

+5
source share
2 answers

Assuming you are using Device Management cmdlets, I would suggest using the Get-Device cmdlet provided in the same package to go through the pipeline.

After a quick look, I found that the Disable-Device does not take any of the DeviceName or DriverVersion from the pipeline - and will not recognize, since this is only an identification parameter ( -TargetDevice ).

On the technologistโ€™s page it is indicated to disconnect the 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 can simply use something like this, assuming your devicename is similar with the Get-Device cmdlet:

 Get-Device | where {$_.name -like "I2C*"} | Disable-Device 
+3
source

at least with Windows 10 it is much simpler:

 $d = Get-PnpDevice| where {$_.friendlyname -like "I2Cwhatever*"} $d | Disable-PnpDevice -Confirm:$false $d | Enable-PnpDevice -Confirm:$false 
+3
source

Source: https://habr.com/ru/post/1209690/


All Articles