Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to use PowerShell to Remove "Hidden" Devices - A Scripting Question

$
0
0

I am new to PowerShell. I am impressed with what I learned. In some instances it is easy to use. It others it is pure frustration.

On boot or after removing a USB device I get USB errors. In other words when there are no USB devices in the Hub I get error messages. Not really a problem just an annoyance.In Device Manager I see many devices that are hidden.

In the past deleting hidden devices from Device Manager has removed these errors messages. But there are many hidden devices in Device Manager. So I gave myself the challenge of using PowerShell Commands to find and remove these devices. Below is what I have done and where I'm having a problem/question. This is not a question about USB errors or about proper use of Device Manager. This is a PS scripting question. 

To find questionable devices:

get-pnpdevice -status unknown

To get the instanceid of these devices:

get-pnpdevice -status unknown | select instanceid

The closest I can find to a remove device PS cmdlet is: disable-pnpdevice This does not seem like the correct cmdlet because an unknown device is likely already disabled. But what the heck.

Get-PnpDevice -Status UNKNOWN | select instanceid |Disable-PnpDevice

The above PS gives the following error. 

Disable-PnpDevice : Generic failure
At line:1 char:52
+ Get-PnpDevice -Status UNKNOWN | select instanceid |Disable-PnpDevice
+                                                    ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Win32_PnPEntity...6-11E7-92BB...)
   :ROOT\cimv2\Win32_PnPEntity) [Disable-PnpDevice], CimException
    + FullyQualifiedErrorId : HRESULT 0x80041001,Disable-PnpDevice

Now I'm stumped. If I should not have used the disable-pnpdevice cmdlet, then what cmdlet should have been used? If its just the syntax, then where did I go wrong?

Steve


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>