Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save aduzsardi/c83f17a6556eb3ef41d5b8274760e39b to your computer and use it in GitHub Desktop.
Save aduzsardi/c83f17a6556eb3ef41d5b8274760e39b 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