0

I have a working script to disable 4 usb joysticks using their respective InstanceID's

$pnpIds = 'HID\VID_0079&PID_0006\7&1699A0E&198&0000', 'HID\VID_0079&PID_0006\7&5438EB5&19D&0000', 'HID\VID_0079&PID_0006\7&390C5738&17D&0000','HID\VID_0079&PID_0006\7&2652A693&16C&0000'

foreach ($pnpId in $pnpids) {
Disable-PnpDevice -InstanceId $pnpId -Confirm:$false

}

It works fine when executing, problem is upon reboot the ID's change.. only 3 characters change at the end in between the "&" characters (HID\VID_0079&PID_0006\7&1699A0E&198&0000 The rest remains the same. Anyway to use wildcards for those 3 characters?

If not is there a way to write a script that will fetch the current InstanceID's for the USB joysticks then disable/enable them with the script I currently am using? Way out of my league here..

drewjbx
  • 1
  • 2
  • Try just running `Get-PnpDevice -Class 'USB'` and see if they have FriendlyNames. Then use those to get the InstanceID's – Theo Oct 20 '21 at 12:32
  • do you know how I can view onscreen output properly? The instance id's are being cut off - USB\VID_046D... – drewjbx Oct 20 '21 at 19:16
  • Try `Get-PnpDevice -Class 'USB' | Format-List` – Theo Oct 20 '21 at 19:23
  • Thanks, I outputted it to a text file. So I see this for instance ID - USB\VID_046D&PID_C534\7&4096F64&1&5 however when I try to disable I get an error. The instance ID I pulled from right click properties shows HID... could that be the problem? HID\VID_0079&PID_0006\7&1699A0E&1A0&0000 – drewjbx Oct 20 '21 at 19:52
  • HID means Human Interface Device. I think you tried to disable the wrong device there – Theo Oct 20 '21 at 20:08
  • I found the full solution from user Capt. Whale at Super User. Along with your help as well I now have a working script. Thanks! – drewjbx Oct 20 '21 at 21:33

1 Answers1

0

Here is the solution from Capt. Whale at Super User. Thankyou!

 $pnpIds = 
  'HID\VID_0079&PID_0006\7&1699A0E&*&0000',
  'HID\VID_0079&PID_0006\7&5438EB5&*&0000',
  'HID\VID_0079&PID_0006\7&390C5738&*&0000',
  'HID\VID_0079&PID_0006\7&2652A693&*&0000'
  foreach ($pnpId in $pnpids) {
  Get-PnpDevice -InstanceID $pnpId | 
    Where Status -Like 'OK' |
      Disable-PnpDevice -Confirm:$false

}

To enable - Enable-PnPDevice

Then replace - Where Status -Like 'OK' To - Where Status -Like 'Error'

The status of the device will be 'error' since it was disconnected.

Link to original thread for the solution - https://superuser.com/questions/1682707/script-to-disable-enable-pnp-device-using-instanceids-but-the-ids-change-upo

drewjbx
  • 1
  • 2
  • 1
    Can you include a link to the Super User thread where you took this code? – Jeremy Caney Oct 21 '21 at 00:42
  • And did you upvote @Cpt.Whale on Super User? P.S. Here's the [link](https://superuser.com/a/1682805/1131396) – Theo Oct 21 '21 at 13:13
  • Also, to Enable, you need to use [Enable-PnpDevice](https://learn.microsoft.com/en-us/powershell/module/pnpdevice/enable-pnpdevice?view=windowsserver2019-ps) – Theo Oct 21 '21 at 13:17
  • Link to superuser thread added, Cpt.Whale has been upvoted. Thx for the tips Theo – drewjbx Oct 22 '21 at 01:11