How to uninstall a Device in script?

pSyToR 96 Reputation points
2020-12-05T13:56:06.86+00:00

So here is the situation to make sure it's well understood.

I have 2 HP packages that I need to install on Windows 10 systems to have the Function Keys reacting properly (for Example Brightness up-down etc).

As a good practice we always create our script with Install / Uninstall option.

One of the package is a simple HP Service Framework this is an Easy Install / Uninstall.

The second package is actually drivers for the keyboard and I cannot see it as an app (so cannot be easily uninstalled). It's only updating the drivers on the computer, so the Generic Keyboard becomes the HP Keyboard.

I found how to remove the Driver package on the computer, so this way once I can remove the keyboard and it won't reinstall with that driver, but take the default PS2 drivers once uninstalled.

$oemfiles = Get-ChildItem c:\windows\inf\oem*.inf
foreach($file in $oemfiles){
    if(get-content $file | select-string -pattern 'hpkeyboard' -SimpleMatch)
        {PnPUtil /Delete-Driver $file.name /force }
}

So now that I did that, how can I uninstall the actual device. (As if I would go in Device Manager and Right Click Uninstall the Keyboard).

PnPUtil only removes the package from Windows. Disable-PNPDevice, well I don't want to disable it, I want to remove it from the system so it goes back to the Default Keyboard.

Also tried Get-Wmiobject, from another thread, but it didn't work, so either it was written wrong, or it's actually not the right way of doing it.

If you are asking why I want to remove the Device completely, is that if you leave this keyboard there, the Function keys are looking for the HP Software Framework and gives a constant error message if you press on the key. (Which is annoying).

Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. pSyToR 96 Reputation points
    2020-12-05T20:31:39.467+00:00

    I did not find a solution, as I went back to the drawing board, and found out I was using and older method for doing what I required.

    Found the problem driver files and was able to do everything in 15 minutes...

    If you read this thread... Some times going back to basic and starting from the beginning one more time might help ;o)

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Rich Matheisen 47,901 Reputation points
    2020-12-05T15:50:45.997+00:00

    Is running DevCon an option? devcon

    The web page says it can "Remove a device from the device tree and delete its device stack".


  2. Praveen 1 Reputation point
    2022-01-12T06:28:21.167+00:00

    As i did recently i am using Devicecon.exe or deviceconx64.exe can only Enable/disable or Remove the device, it canot uninstall the device. driver can be uninstall but not device.

    if you find any way let know here.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.