Cleanup orphan/hidden devices

Page 1 of 2 12 LastLast

  1. Posts : 2,450
    Windows 10 Pro x64
       #1

    Cleanup orphan/hidden devices


    I have been following this thread, trying to fix the problem with the erroneous USB flask disks icons.
    According to the fix recommendation -which worked perfectly- there is a need to clear all phantom USB/Volume/Portable Devices from Device Manager.
    That is a cumbersome task, especially if the number of these unneeded devices grows significantly over time. In my case there were 90 of them, so I had to select 90 devices and delete them one by one in Device Manager. Apparently there was a need for a more automated process to delete them.

    Trying to find a better way I came through a post from one of our distinguished fellow members, Ed Tittel
    EdTittel said:
    Uwe Sieber's tools are truly awesome. It's worth spending some time poking around the site: Tools for Windows. Device Cleanup is terrific, but he's got lots of other good stuff, too.
    --Ed--
    The recommended by Ed 3rd party app, seems to be working as it’s supposed to and helps delete hidden/phantom devices.

    But… this, after all, is TenForums and we’re accustomed in doing things “our way”, i.e. with Microsoft’s own tools.

    So to start, you can view all orphan devices, i.e. devices that are not currently connected to your computer
    Open Device Manager and click View > Show hidden devices.
    All devices in gray color are not currently connected to your computer.
    Some of these devices, like old USB flash disks, or old external disks are not needed and can be safely removed.
    This can be done in Device Manager, as said before, by pressing delete on these hidden devices.

    Cleanup orphan/hidden devices-dm.png

    Automating this process, to be able to delete multiple devices at once, can be done with the use of a simple PowerShell script, with the help from Microsoft’s Device console tool, DevCon.

    DevCon (Devcon.exe), the Windows Device Console, is a command-line tool that displays detailed information about devices on computers running Windows. You can use DevCon to enable, disable, install, configure, and remove devices. In other words, it's the command line alternative of Device Manager.

    If you don’t already have this tool, you can get it easily by following these steps.
    The DevCon.exe tool is provided free of charge as part of the Windows Driver Kit.

    1. Use this link to download the latest Windows 10 Driver Kit. https://go.microsoft.com/fwlink/?linkid=2085767
    2. Run the file and choose "Download the Windows Driver Kit for installation on a separate computer.
    3. Once the WDK is downloaded go to the location you saved it and within the Installers folder find the file 787bee96dbd26371076b37b13c405890.cab
    4. Using 7zip (or your favorite file extractor), open the cab file and extract the file named: filbad6e2cce5ebc45a401e19c613d0a28f
    5. Rename this file to devcon.exe and there you have it. The latest devcon.exe


    Now to cleanup these unwanted orphan devices.

    1 Go to your desktop and create a folder (e.g. Cleanup).

    2 Copy the devcon.exe file and paste it in that folder.

    3 Download the PowerShell script RemoveHiddenDevices.ps1.

    Download

    4 Save it in the Desktop folder where the devcon.exe is located and unblock it.

    5 Open Powershell as Administrator and navigate to the folder where the PowerShell script and the devcon.exe reside.


    If you haven't already changed the PowerShell ExecutionPolicy to allow running scripts, you need to do it. So before running the script (or any other script, from a source you trust), run the following command to allow the script to run in the current PowerShell session.

    Set-ExecutionPolicy Bypass -Scope Process

    Remember that closing the PowerShell window your ExecutionPolicy returns to its defaults, for every new PowerShell window (session).


    6 Run the script by typing the command: .\RemoveHiddenDevices.ps1

    7 Upon execution of the script, a new PowerShell window (Out-Gridview) will open, in which all the hidden devices that are allowed to be deleted will be presented, so you can select which devices you want to remove.

    Note   Note
    The hidden, orphan devices, that are allowed to be removed and will be shown in that selection window, are the ones that are greyed-out in Device Manager, under the following classes:
    • Disk Drives (DiskDrive)
    • Portable Devices (WPD)
    • Storage Volumes (Volume)
    • Universal Serial Bus Controllers (USB)


    Cleanup orphan/hidden devices-script1.png

    8 Go through that list carefully and select the hidden devices that you want to remove. Select all devices by pressing Ctrl+A, or select some of the devices by holding down Ctrl while selecting each device.

    9 Once you selected the devices you want to remove, press the OK button at the bottom of this window.

    The selection window will be closed and you will be moved to the underlying PowerShell console window where you’ll see the results of the script.

    Cleanup orphan/hidden devices-script2.png

    That's it. You have cleaned the hidden/orphan devices from your system.
    You can now close the PowerShell window, if you wish.... as Shawn @Brink would have said!

    HTH!
    Last edited by ddelo; 23 Nov 2019 at 18:19.
      My Computer


  2. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #2

    Looks like UWE's DeviceCleanup.exe by itself is sufficient, why the additional stuff? Not knocking it, but where is the payback?
      My Computers


  3. Posts : 2,450
    Windows 10 Pro x64
    Thread Starter
       #3

    Ztruker said:
    Looks like UWE's DeviceCleanup.exe by itself is sufficient, why the additional stuff? Not knocking it, but where is the payback?
    No payback Rich. Just using Microsoft's tools, instead of 3rd party ones and having total control over what to choose to delete, via altering the PowerShell query!
      My Computer


  4. Posts : 14,046
    Windows 11 Pro X64 22H2 22621.1848
       #4

    Ah, got it. More work, no gain. Sounds like my life before retirement.
      My Computers


  5. Posts : 2,450
    Windows 10 Pro x64
    Thread Starter
       #5

    Ztruker said:
    Ah, got it. More work, no gain. Sounds like my life before retirement.
    I'm still young for retirement....only 56. So that explains it!
      My Computer


  6. Posts : 4,224
    Windows 10
       #6

    Nice job, Dimitri. Always nice to learn more about official channels!
    Thanks,
    --Ed--
      My Computers


  7. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #7

    Good information here, Dimitri.

    Thanks!
      My Computer


  8. Posts : 2,450
    Windows 10 Pro x64
    Thread Starter
       #8

    EdTittel said:
    Nice job, Dimitri. Always nice to learn more about official channels!
    Thanks,
    --Ed--


    Compumind said:
    Good information here, Dimitri.

    Thanks!

    Ed, Brian, thanks a lot guys.
    Glad you found it useful
      My Computer


  9. Posts : 5,048
    Windows 10/11 Pro x64, Various Linux Builds, Networking, Storage, Cybersecurity Specialty.
       #9

    Thanks to Ed as well!

    Good resource. Very familiar to me.

      My Computer


  10. Posts : 2,450
    Windows 10 Pro x64
    Thread Starter
       #10

    Compumind said:
    Thanks to Ed as well!
    Ed, deserves credit for a lot of things Brian....for this one too!
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 21:25.
Find Us




Windows 10 Forums