Script to disable/enable PnP Device using InstanceID's - but the ID's change upon reboot
You can! The best place to start is with just Get-PnpDevice
, to make sure that you're only selecting the devices you expect to:
# use * as a wildcard
Get-PnpDevice -InstanceId 'HID\VID_0079&PID_0006\7&1699A0E&*&0000'
# example output on my PC:
Status Class FriendlyName InstanceId
------ ----- ------------ ----------
OK Keyboard HID Keyboard Device HID\VID_0079...
OK Mouse HID-compliant mouse HID\VID_0079...
Then you can use basically the same script (I'm guessing on where the wildcard goes):
$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
}
You cannot use a wildcard in Disable-PnpDevice
, but it will disable any device(s) piped to it, including lists of multiple devices, so be careful that you don't disable anything accidentally.
Get-PnpDevice
can also use a wildcard for searching by -FriendlyName
or -Class
if that's easier.