17

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?

Richard
  • 6,812
  • 5
  • 45
  • 60
pewpewPenguin
  • 171
  • 1
  • 1
  • 4
  • What was the error given, when you have `| Disable-Driver` on the end? – James Ruskin Dec 22 '14 at 09:37
  • I translate it, Disable-Device: The name "Disable-Device" was no name of a Cmdlet, or a function, or a script file, or an executive program. Check the notation of the name, or if it is the right path and try again. – pewpewPenguin Dec 22 '14 at 10:21
  • I have a working example over at https://github.com/StingyJack/VidyaRestart – StingyJack Jan 15 '17 at 15:01

2 Answers2

22

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
Falco Alexander
  • 3,092
  • 2
  • 20
  • 39
  • 1
    This is great! You could also chain all these commands directly together. – marsze Nov 29 '18 at 13:10
  • 2
    This works for me only if I run it in an admin console, otherwise I get an excepetion: … FullyQualifiedErrorId : HRESULT 0x80041001,Disable-PnpDevice – Mehrdad Mirreza Jan 07 '20 at 08:09
  • 2
    Of course you shouldn't expect _anything_ that touches device drivers to work in a standard console. – SilverbackNet Feb 28 '20 at 23:56
  • Too bad. Chaining doesn't work for me. It won't enable the device again. With three separate lines it works. – mplwork Aug 12 '21 at 10:41
4

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
James Ruskin
  • 808
  • 7
  • 13
  • An error appears by trying the your last suggestion. "The naming "Get-Device" was no name of a Cmdlet, a function or..." Do I have to write a full script? (I currently put this command into the powershell) – pewpewPenguin Dec 22 '14 at 10:26
  • Okay, as a first step, `Disable-Device` isn't a standard cmdlet on Windows 8. If you've found it from a post like [this](http://blogs.technet.com/b/wincat/archive/2012/09/06/device-management-powershell-cmdlets-sample-an-introduction.aspx), you'll notice that it suggests using the Device Management cmdlets (link in answer), which contains `Disable-Device` and `Get-Device`. You'll need to download and import this module before you can use any of the commands contained within. – James Ruskin Dec 22 '14 at 10:30
  • I tried to import the module (put in into the powershell folder modules) and "Import-Module .\PSCmdlet.psd1 -Verbose" as it says in the .txt, but it always says file not found. – pewpewPenguin Dec 22 '14 at 12:21
  • Assuming you put it in one of the modules folders (e.g. `C:\Users\pewpewPenguin\Documents\WindowsPowershell\Modules`), `ipmo DeviceManagement` should import it. – James Ruskin Dec 22 '14 at 14:02
  • now it throws this: `Import-Module : The 'C:\Users\pewpewPinguin\Documents\WindowsPowerShell\Modules\DeviceManagement\DeviceManagement.psd1' module c annot be imported because its manifest contains one or more members that are not valid. The valid manifest members are ('ModuleToProcess', 'NestedModules', [...] then try to import the module again. [...] – pewpewPenguin Dec 23 '14 at 06:34
  • The one named DeviceManagementCmdlet.dll doesnt work on windows 10 64bit. Try to make sure you get the one with DeviceManagement.dll. – StingyJack Oct 28 '17 at 16:01