Microsoft Hyper-V has been around for over a decade currently, and per se, it is had many times to mature. For the foremost half, Hyper-V could be a terribly stable and reliable enterprise-class hypervisor. Even so, things can, and typically do fail. Regarding four or 5 months gone as an example, I bumped into a state of affairs during which all of the virtual machines on a selected host suddenly lost the power to access the net. To the current day, I can’t make a case for what happened; as a result of no configuration changes were being created. The purpose is that though you would possibly not be able to stop a Hyper-V virtual network drawback from occurring, it’s an honest plan to understand what your choices area unit for fixing any issues that do occur. During this article, i will be able to show you one amongst the tools that i prefer to use.

Lately, I even have been employing a PowerShell-based tool to repair issues with Hyper-V virtual networks. Before I show you ways this tool works, I want to denote that it’s not enclosed in native PowerShell. The tool is truly a section of System Center Virtual Machine Manager, and is meant to be run through the Virtual Machine Manager Command Shell.

So what’s this tool? The associated cmdlet is Repair-SCVirtualNetwork.

Using the PowerShell cmdlet:
Using the Repair-SCVirtualNetwork cmdlet is typically pretty straightforward and easy. You’ll typically simply need to determine the virtual network that you simply need to repair. What will create this a small amount difficult, however, is that it’s common for multiple Hyper-V hosts to use a typical virtual switch name.

Let’s fake for a flash that I even have 2 Hyper-V hosts named Hyper-V-1 and Hyper-V-2. Let’s conjointly fake that I even have a virtual machine named VM1 running on Hyper-V-1, which i need to measure migrate that VM to Hyper-V-2. If that live migration is to be utterly seamless, then Hyper-V-2 can got to be provisioned with a virtual switch that has constant name because the virtual switch that VM1 is presently victimization on Hyper-V-1. the tip result’s that there’ll be multiple virtual switches with constant name.

If you would like to ascertain a a lot of concrete example, then look at the screen capture below. During this image, I even have entered the Get-SCVirtualNetwork cmdlet. I then used the Select-Object cmdlet to specify that I needed to ascertain the virtual network name, and therefore the name of the Hyper-V host on that the virtual network’s virtual switch resides. As you’ll see within the figure, I even have many Hyper-V hosts that contain a virtual network named My Virtual Switch.

Virtual Networks Problem and workaround:

Unfortunately, the Repair-SCVirtualNetwork PowerShell cmdlet doesn’t contain a parameter that permits you to specify that a repair ought to be created against a particular host. The cmdlet solely permits you to provide the name of the virtual network that you simply need to repair. Therefore however does one get round the drawback of getting identical virtual network names on multiple hosts?

Before I show you ways to unravel this drawback, i need to point out you that in some convoluted approach, System Center conjointly treats these identically named virtual switches as if they were one virtual network, even if they’re truly separate entities. Let Maine show you what I mean.

If you open the Virtual Machine Manager console, visit the VMs and Services space, and so click on VM Networks, you’ll see an inventory of the VM networks that exist at intervals your organization. If you verify the figure below, you’ll notice that the console solely displays one instance of My Virtual Switch, even if the All Hosts cluster clearly contains every of the hosts that were shown within the previous screen capture.

Additionally, if I were to right click on the virtual switch, and opt for the read Dependent Resources command from the road menu, i might see an inventory of all of the virtual machines that rely upon this virtual switch. These virtual machines area unit distributed across the hosts in my organization. Incidentally, my Hyper-V hosts don’t seem to be clustered.

Since there area unit multiple instances of the virtual network in question, the primary issue that must be done before repairing the virtual network is to map those virtual network instances to a variable. By doing therefore, I will slim things down so I solely reference one virtual network. this is often necessary, as a result of the Repair-SCVirtualNetwork PowerShell cmdlet can fail if you are attempting to run it against multiple virtual networks right away.

Normally, this is often the approach that you simply would map a virtual network to a variable:

$VirtualNetwork = Get-SCVirtualNetwork -Name “My Virtual Switch”

However, since the goal is to capture one virtual network, we want to append a filter. That way, we are able to specify that host’s virtual network we wish to look at. Here is what the command appearance like:

$VirtualNetwork = Get-SCVirtualNetwork -Name “My Virtual Switch” | Where-Object {$_.VMHost -eq “”}

If you verify the screenshot below, you’ll see that the variable that I even have outlined points to one virtual network, on one host.

With the virtual networks mapped to a variable, we are able to launch the repair method. As antecedently mentioned, all you’ve got to try and do is run the Repair-SCVirtualNetwork cmdlet, and append the name of the virtual network that you simply need to repair. Since the virtual network instance has been mapped to a variable during this case although, we want to reference the variable instead of providing associate degree actual virtual network name. Here is what the command would look like:

Repair-SCVirtualNetwork -VirtualNetwork $VirtualNetwork

Leave a Reply

Your email address will not be published. Required fields are marked *

Enter Captcha Here :