Skip to content

Instantly share code, notes, and snippets.

@trolldbois
Created September 3, 2020 14:26
Show Gist options
  • Save trolldbois/294b61d06e5ad300eaf092f0101098b1 to your computer and use it in GitHub Desktop.
Save trolldbois/294b61d06e5ad300eaf092f0101098b1 to your computer and use it in GitHub Desktop.
Powershell to cleanup the ghost virtual NetAdapters created for HyperV
$adapterName = "Hyper-V Virtual Ethernet Adapter"
$badAdapters = Get-NetAdapter | ? {$_.InterfaceDescription.StartsWith($adapterName) -and $_.Status -ne "Up"}
$badAdaptersName = $badAdapters | select -ExpandProperty InterfaceDescription
$badGUID = Get-WmiObject win32_networkadapter -Property guid,Name | ? {$badAdaptersName.Contains($_.Name)} | select -ExpandProperty GUID
foreach ($GUID in $badGUID) {
Write-Host "Removing $GUID" -ForegroundColor Cyan
$RemoveKey = "HKLM:\SYSTEM\ControlSet001\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}\$GUID"
# Get-Item $RemoveKey | GCI
Remove-Item -Recurse $RemoveKey
}
# that worked
# cleanup
$reg_base = "HKLM:\SYSTEM\CurrentControlSet\Services\vmsmp\parameters\NicList"
foreach ($nic in gci $reg_base) {
$guid = (($nic | Get-ItemProperty ).DeviceGuid).split("\")[2]
if ( $badGUID.Contains($guid) ) {
$RemoveKey = "HKLM:$($nic.Name)"
Write-Host "Removing $RemoveKey" -ForegroundColor Cyan
Remove-Item -Recurse $RemoveKey
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment