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..
CodePudding user response:
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