guidox / Hardware

Show Non-Present Devices in Device Manager and Clean Them Up

TL;DR

Set **devmgr_show_nonpresent_devices=1**, open Device Manager with **Show hidden devices**, then uninstall the greyed entries you no longer use.

Before you start

Requirements

  • Admin rights
  • 10 minutes
Step by step

Instructions

01

Count the ghost devices first

**Get-PnpDevice** lists present and non-present devices separately. The count of non-present entries shows whether a cleanup is worth the risk.

Get-PnpDevice | Group-Object Present | Select-Object Name,Count
Get-PnpDevice -PresentOnly | Measure-Object
(Get-PnpDevice | Where-Object { -not $_.Present }).Count
02

Turn on the hidden view

The variable is read by the Device Manager process at start. Set it in the machine environment so the setting survives a new shell.

[Environment]::SetEnvironmentVariable('devmgr_show_nonpresent_devices','1','Machine')
$env:devmgr_show_nonpresent_devices = '1'
devmgmt.msc
# View > Show hidden devices
03

Find the devices worth removing

A ghost with a problem code or one that holds a COM port is worth removing. A device you may plug in again is not: Windows will reinstall it, but the profile is lost.

Get-PnpDevice | Where-Object { -not $_.Present } | Select-Object Class,FriendlyName,InstanceId | Sort-Object Class
Get-PnpDevice -Class Ports | Where-Object { -not $_.Present } | Select-Object FriendlyName,InstanceId,Status
04

Remove one entry from the command line

**pnputil /remove-device** removes a specific instance by its InstanceId. That is precise and does not touch present hardware.

$id = (Get-PnpDevice | Where-Object { -not $_.Present -and $_.FriendlyName -like '*USB Serial*' } | Select-Object -First 1).InstanceId
$id
pnputil /remove-device "$id"
Get-PnpDevice | Where-Object InstanceId -eq $id
05

Clean a whole class when it is safe

Removing every non-present entry of one class fixes port and letter conflicts. Do it per class, never across the board, and never for storage controllers.

Get-PnpDevice -Class Ports | Where-Object { -not $_.Present } | ForEach-Object { pnputil /remove-device $_.InstanceId }
Get-PnpDevice -Class Ports | Select-Object FriendlyName,Present,Status
06

Rescan and verify

A scan for hardware changes restores anything that is actually connected. The remaining list should show only the hardware you own.

pnputil /scan-devices
Get-PnpDevice -PresentOnly | Group-Object Class | Select-Object Name,Count | Sort-Object Count -Descending
Get-PnpDevice | Where-Object { -not $_.Present } | Measure-Object
Troubleshooting

Common issues

Ghost devices are still hidden

Device Manager reads the variable when it starts. Close all instances, set the variable in the same shell, then open devmgmt.msc again.

A COM port number is still taken

The ghost entry holds it. Remove that instance, then the port number becomes available again.

The device came back but with a new number

Windows assigns the next free port. Set the old number manually in the port's advanced settings.

pnputil says the device cannot be removed

It is present, or a driver is bound and in use. Remove non-present entries only.

FAQ

Frequently asked

Does removing a ghost delete the driver?

No. The instance goes, the driver package stays in the store until you remove it separately.

Can I break something with this?

Removing a non-present device is low risk, but removing present storage or HID devices can leave the machine without input. Stay on the greyed entries.

Why are there so many?

Each new plug-in with a different serial number creates a new instance. Docks and card readers produce one per port.

How to undo this

Set devmgr_show_nonpresent_devices back to 0, or delete the variable. Removed devices reappear when you plug the hardware in again.

Changelog · 1 entry
  1. 2026-11-01
    First version
Interactive version: checklist, feedback, related guides →

Free · no account needed · tracks your progress