Created
September 3, 2020 14:26
-
-
Save trolldbois/294b61d06e5ad300eaf092f0101098b1 to your computer and use it in GitHub Desktop.
Powershell to cleanup the ghost virtual NetAdapters created for HyperV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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