Delete hardware device

Hey guys,

So I’ve been looking for a way to delete a hardware device, preferably using some sort of one-liner.

Using “Get-PnpDevice” you can list all devices, but strangely enough actually deleting them isn’t an option.
Now I know, there’s a function out there that relies on the “Win32.SetupApi” that can list and delete devices.
But I haven’t been able to filter out the command to just delete a device.

At this moment I’m stuck with this line, but I can’t wrap my head around how it actually works:

[pre][Win32.SetupApi]::SetupDiRemoveDevice($Devs, [ref]$DevInfo)[/pre]

Does anyone out here know a way to delete a device in a PowerShell fashion?

Regards,

BM

Do, you just want to disable or really remove the device?

https://docs.microsoft.com/en-us/powershell/module/pnpdevice/disable-pnpdevice?view=win10-ps

Even if you removed it, PnP will just add it back on reboot, unless it’s an external device that you can physically unplug.

Did you try and use Devcon.
https://support.microsoft.com/kb/311272

See also:
How to Manage Device Drivers with Command Line
https://social.technet.microsoft.com/wiki/contents/articles/181.how-to-manage-device-drivers-with-command-line.aspx