I've been tasked with coming up with a script that will remove hidden devices from VMs. Anyone who's used VMs before knows that sometimes "ghost" devices show up. We've had a few problems recently and would like to write a script that will, on startup, remove any of these hidden devices (yes, I'm fully aware some may be needed, we have logic that will not nuke them all).
Say I have an array that contains devices in WMI type format, let's call that list "$devices"
How would I remove each one using powershell? I've tried devcon, but I feel like I'm not getting the syntax right, my script is doing the following:
foreach ($device in $devices){
$toremove = $device.name
c:\windows\system32\devcon.exe remove $toremove
}
Is there a better tool than devcon, like maybe a PowerShell cmdlet (even one I have to download from somewhere)? If not, could someone help me get my syntax right (or tell me I need to use invoke- ?)
Thanks in advance.


