使用devcon配合poweshell自动批量删除windows已移除的隐藏设备com口
$env:DEVMGR_SHOW_NONPRESENT_DEVICES=1
$ghostDevices = Get-PnpDevice | Where-Object { $_.Status -eq 'Unknown' }
foreach ($device in $ghostDevices) {
Write-Output "Removing device: $($device.Name) with InstanceId: $($device.InstanceId)"
& '.\devcon.exe' remove "@$($device.InstanceId)"
}
Write-Output "Removal process completed."