I wrote this script to automate the part of removing those pesky Unknown Devices that show up when lets say you are creating your reference or master XP image. All this script does is queries WMI for any pnp devices that have a status of Error and uses devcon to remove them. This is perfect for placing right before the sysprep step in your BDD automation.
P.S. This script only detects unknown devices that have already been marked as ‘Error’. Therefore devices that are prompting the wizard for drivers may not be detected with this script. Luckily it seems that BDD unattended install of XP marks all the unknowns as Error’s right away so it should work.