Skip to content

Instantly share code, notes, and snippets.

@rgl
Created October 22, 2016 23:21
Show Gist options
  • Save rgl/ed3352d676a68e259e38cd2d3bce0049 to your computer and use it in GitHub Desktop.
Save rgl/ed3352d676a68e259e38cd2d3bce0049 to your computer and use it in GitHub Desktop.
Remove all VirtualBox Host-Only network interfaces (Windows)
# NB this depends on devcon. you must install it from chocolatey with choco install -y devcon.portable
$devcon = "$ENV:ProgramData\Chocolatey\Lib\devcon.portable\Devcon$(if ($ENV:PROCESSOR_ARCHITECTURE -like '*64') {'64'} else {'32'}).exe"
Get-NetAdapter `
| Where-Object {$_.Virtual} `
| Where-Object {$_.DriverFileName -like 'VBox*.sys'} `
| ForEach-Object {
Write-Host "Removing the $($_.InterfaceAlias) interface..."
$result = &$devcon remove "@$($_.PnPDeviceID)"
if (!($result -eq '1 device(s) were removed.')) {
throw "failed to remove the network interface $($_.InterfaceAlias): $result"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment