identify all instance id's in output of pnputil and then sends remove-device command for each

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Locked
Message
Author
imyashy
Posts: 9
Joined: 10 Dec 2023 17:05

identify all instance id's in output of pnputil and then sends remove-device command for each

#1 Post by imyashy » 22 Dec 2023 16:24

Hi Gents,

I'm looking for some help please. I need a batch script that identifies all instance id's using an output from pnputil and then removes the corresponding devices according to their instance id. I am using windows 10 and windows 11.


1. Run's pnputil /enum-devices /class "smartcardreader"

Code: Select all

Microsoft PnP Utility

Instance ID:               [color=#BF0000] USB\VID_09D8&PID_0428\8&25de01d1&0&2[/color]
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Disconnected
Driver Name:                wudfusbcciddriver.inf

Instance ID:                [color=#BF0000]USB\VID_09D8&PID_0428\6&1801434e&0&2[/color]
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Started
Driver Name:                wudfusbcciddriver.inf

Instance ID:                [color=#BF0000]USB\VID_09D8&PID_0428\8&1324512c&0&2[/color]
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Disconnected
Driver Name:                wudfusbcciddriver.inf

Instance ID:                [color=#BF0000]USB\VID_076B&PID_3031\7&3adb5428&0&1[/color]
Device Description:         OMNIKEY 3x21
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          HID Global
Status:                     Started
Driver Name:                oem5.---

Instance ID:                [color=#BF0000]USB\VID_076B&PID_3031\7&3adb5428&0&2[/color]
Device Description:         Microsoft Usbccid Smartcard Reader (WUDF)
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          Microsoft
Status:                     Disconnected
Driver Name:                wudfusbcciddriver.inf

Instance ID:                [color=#BF0000]USB\VID_076B&PID_5121\OKCM0021802141932272863198160893[/color]
Device Description:         OMNIKEY 5x21
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          HID Global
Status:                     Disconnected
Driver Name:                oem11.---

Instance ID:                [color=#BF0000]USB\VID_076B&PID_3021\7&3adb5428&0&1[/color]
Device Description:         OMNIKEY 3x21
Class Name:                 SmartCardReader
Class GUID:                 {50dd5230-ba8a-11d1-bf5d-0000f805f530}
Manufacturer Name:          HID Global
Status:                     Disconnected
Driver Name:                oem3.---
2. Remembers all the instance IDsin the above output or outputs them to a temporary txt file i.e. instanceids.txt
3. Run's pnputil /remove-device "instance id" for each instance id remembered or outputted in the txt file above. When using the /remove-device command the instance ids should have a " before and after

e.g /pnputil /remove-device "USB\VID_076B&PID_5121\OKCM0021802141932272863198160893"

Any help would be appreciated.

Squashman
Expert
Posts: 4470
Joined: 23 Dec 2011 13:59

Re: identify all instance id's in output of pnputil and then sends remove-device command for each

#2 Post by Squashman » 22 Dec 2023 17:00

1)Pipe the output to the FINDSTR command to isolate the Instance ID.
2) Capture that command output with a FOR /F command like you have done in other batch files.
3) Run the command to remove the device with that output.

Make an attempt.

Locked