繁体   English   中英

PowerShell禁用并启用驱动程序

[英]PowerShell disable and enable a driver

有时在重新启动/冷启动后,Win8中的触摸屏驱动程序出现了问题,因此,现在必须手动重新启动它。

因此,我想编写一个在登录后启动的脚本,它将禁用驱动程序并再次启用它。

我实际上找到了驱动程序,并且可以通过以下方式获得驱动程序的对象列表:

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

但是在行尾添加“ | Disable-Device ”将不起作用。

谁能告诉我如何正确编写命令并像批处理文件一样启动脚本?

至少在Windows 10上要容易得多:

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

假设您正在使用设备管理cmdlet ,建议您使用同一包中提供的Get-Device cmdlet来传递管道。

快速浏览后,我发现Disable-Device不会从管道中获取DeviceName或DriverVersion之一,也不会识别这两者,因为它只是标识参数( -TargetDevice )。

technet页面建议禁用设备:

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

您可以简单地使用如下所示的方法,假设您的设备名称与Get-Device cmdlet相似:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM