Windows 7 NIC Detection Issue / Script to Remove then Add the NIC Back


One of my customers has been having an intermittent issue with their Windows 7 VDI Desktops.  Occasionally after they update the Operating System, when the desktops boot back up they fail to use their NICs.  The NIC is still attached to the VM and is still on the right network, but Windows fails to recognize it (it doesn’t get a DHCP address and, in fact, registers within the OS as being physically disconnected from the network).  Restarting the desktop doesn’t help, reinstalling drivers doesn’t help (we’re using the VMXNET3 network adapter, for those who are interested).  Removing the adapter from Windows seems to be the key to getting the desktop back online.  We’ve gotten desktops back online by removing the adapter from Device Manager and then scanning for hardware changes (and rebooting).  We’ve also removed the NIC from the VM (with the VM shut down) and replaced it; that’s also alleviated the issue.

Unfortunately, those steps just alleviate the symptom.  They get people back up into a working state, but I’ve got no idea what’s actually causing Windows to freak out over its NIC.  Does anyone have any ideas?  Since removing the NIC and adding a new one resolved it, I originally thought that it was related to the specific device (maybe Windows ties something to the MAC address and gets messed up, preventing that card from coming online again), but the problem is alleviated simply by removing the NIC from Device Manager, which allows the same NIC to be rediscovered and function.  That led me to believe that it might be a driver issue, but reinstalling my NIC driver didn’t resolve the issue (and, removing/restoring the NIC doesn’t actually reinstall the drivers)… so now I’m not sure where to look for a solution.

To make life easier, I wrote a quick PowerCLI Script that goes through that process for a list of VMs (you’ll have to provide that list in the array at the start of the script).  The script is super basic, it just identifies the NIC in the current desktop, removes that NIC, Adds a new VMXNET3 NIC to the same network that the original NIC was on, then powers on the VM.  The Script will only run on VMs that aren’t running, so make sure you shut down your desktops before you try this.  As always, this is provided as is with no guarantees and is only for educational purposes.  Also, beware of unintentional line breaks due to the width of the blog.



$OfflineDesktops = @("Desktop1", “Desktop2”, “Desktop3”)
foreach ($VM in $OfflineDesktops){
                $nic = Get-NetworkAdapter -VM $VM
                Remove-NetworkAdapter -NetworkAdapter $nic -Confirm:$false
                New-NetworkAdapter -VM $VM -NetworkName $nic.NetworkName -Type vmxnet3 -StartConnected
                Start-VM -VM $VM
}


Update: I found a reference that sounds suspiciously like this issue at  http://support.microsoft.com/kb/2526142.  Now that I have a hotfix to try, I've been unable to reliably recreate the issue!  I'll post an update if I get to the point where I can reliably provoke this failure and if this hotfix resolves it.

Comments

Popular posts from this blog

Clone a Standard vSwitch from one ESXi Host to Another

PowerShell Sorting by Multiple Columns

Deleting Orphaned (AKA Zombie) VMDK Files