I'm trying to automate via PowerShell a number of time consuming tasks that I have to preform to make a new VM template, one of which is removing all of the NICs from the VM and cleaning up the Device Manager of non present devices.
After removing the NICs from the VM, I've tried using the following code snippets, which do the same thing, to clean up Device Manager.
wmic nic where "(servicename is null)" delete
gwmi win32_networkadapter | ?{$_.ServiceName -eq $null} | rwmi
In both cases I receive the error "Provider is not capable of the attempted operation". Reviewing the event logs for WMI-Activity didn't seem to help: ResultCode = 0x80041024; PossibleCause = Unknown.
Has anyone be able to do something similar that removes the non present devices or is able to find an issue with the above commands?
EDIT: I've tried using DevCon to remove the device, but it seems to only work with present devices. I'm now combing through the registry to see if there is a specific key or set of keys that if removed would remove the NIC from Device Manager.