VMware

Listing RDMs and adding NFS datastores all over the place. | Main | Stuff worth checking out.

June 26, 2009

Finding and fixing VMs connected to missing port groups.

Yesterday someone took the liberty of upgrading one of my ESX servers that I use to run a virtual vSphere lab. Fortunately he was kind enough to preserve all of the VMs, and they were restored and re-registered after the upgrade.

There was one detail that he didn’t notice, which was that my virtual vSphere lab VMs were all connected to an internal network called “Internal”. When I got in today my lab didn’t work at all because there was no networking between vCenter and the ESX hosts or their shared storage. The network cards all said they were attached to the “Internal” network, but there was no Internal network! Fortunately this was pretty easy to fix with PowerCLI.

First, let’s look at a script that will identify any VM that is connected to a non-existent network:

# Search for VMs that are connected to a non-existent portgroup.
$pgNames = Get-VirtualPortGroup | Foreach { $_.Name }
Get-VM | Where { $_ | Get-NetworkAdapter | Where { $pgNames -notcontains $_.NetworkName } }

This code starts by getting a list of all portgroup names. Then it goes through all VMs and identifies any VM that has at least one network adapter connected to a non-existent portgroup. Note that this assumes we are connected directly to ESX. If you need to use something like this against vCenter you should do it on a host-by-host basis. Anyway, when I ran it here was the result:

shot1

These are all the VMs of my virtual lab. Now let’s go about fixing the problem. First, creating the Internal virtual switch and portgroup are pretty easy:

# Create the missing switch and portgroup.
New-VirtualSwitch -Name Internal
Get-VirtualSwitch -Name Internal | New-VirtualPortGroup -Name Internal

Now the portgroup exists but there is one last problem: the VMs are not actually connected to the portgroup. Again, pretty easy to fix.

# The guests that were powered on will still be disconnected, so connect them.
Get-VM | Get-NetworkAdapter | Where { $_.NetworkName -eq "Internal" } |
  Set-NetworkAdapter -Connected:$true -Confirm:$false

With that, everything is back to normal.

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00d8341c328153ef01157164f4a2970b

Listed below are links to weblogs that reference Finding and fixing VMs connected to missing port groups.:

Comments

runescape gold

When you play games, you really thought about the Department of your equipment well enough, your account than others, your gold enough ... There are better! What you want to have here.come on..Let's go

Post a comment

If you have a TypeKey or TypePad account, please Sign In.