Device Cleanup Cmd is the command-line version of Device Cleanup Tool meant for helping remove leftover traces of nonpresent devices.
Every time you attach a device to your machine, it will leave an entry within Windows device management. You have the option to remove those entries directly through the Windows device manager, but when you have numerous entries, this can take some time. Device Cleanup Cmd permits you to select multiple devices or even all of them at once, just like in the GUI version of this program but via the command-line instead.
Usage: DeviceCleanupCmd pattern1 [pattern2] [patternN] [-e:excludepattern1][-t][-s][-m:age][-n] -e:excludepattern pattern not to remove -t test only -s skip creation of a system restore point -m:age minimum 'age' (last use of the device must be at least that old) -n no wait when finished
Patterns are device IDs, device classes or friendly names. Wildcards can be used.
remove all devices whose device IDs begin with HIDVID_045E DeviceCleanupCmd HIDVID_045E*
remove all devices whose device IDs contain VID_045E DeviceCleanupCmd *VID_045E*
remove all bluetooth devices but not COM9 and COM10 DeviceCleanupCmd BTH* -e:"* (COM9)" -e:"* (COM10)"
remove all nonpresent devices whose device class is Media DeviceCleanupCmd Media
remove all devices not used for 1 year or more (m - month, d - days, i - minutes) DeviceCleanupCmd * -m:1y
remove all devices DeviceCleanupCmd *
show which devices would be removed (test mode) DeviceCleanupCmd -t *
Non-PnP devices are not removed.
Similar: The Ultimate List of Every Known Command Prompt and PowerShell Commands PowerShell and Command Prompt 101 How-To Run PowerShell or the Command Prompt as Administrator