Rebuilding Distributed Switch on New vCenter Instance Using a Backup
- Ben Liebowitz
- 0
- 2044
As you may have seen, I recently had a vCenter fail and after working with VMware Support it was determined that the vCenter should be rebuilt from scratch. Rebuilding the vCenter and adding the hosts that were in it was fairly easy. However, restoring their networking was another story. The hosts retained their previous network configuration, but I was unable to make any changes, including adding the hosts to a new distributed switch. Each host displayed this message.
My only course of action was to build a new distributed switch utilizing a backup! Thankfully, I run the script I posted back in 2015 on a regular basis, so I had switch config backups! I built built the new vDS through the UI, but you can script it also. The code to build the new switch utilizing the backup file is below. If you just want the switch with no portgroups, add the -WithoutPortGroups switch. My lab switch was at an older version, so I built my new one at the same version so the configs match up.
New-VDSwitch -Name dvSwitch -Version 6.6.0 -BackupPath c:\ben\vds\10_1_23\vcsa.homelab.local_dvSwitch_.zip
After the new switch is built, you will need to evacuate the VMs off of each host, and access the DCUI via the remote console and restore the standard switch. There is no need to create a standard switch by hand first.
If you use monitoring software, it’s best to enable Maintenance Mode for the VMHost(s), as they will drop during this process temporarily.
First, arrow down to NETWORK RESTORE OPTIONS and hit ENTER.
Choose the option RESTORE STANDARD SWITCH and press ENTER.
Press F11 to confirm.
Once restored, you’ll see the option to restore standard switch is grayed out. Press ESC to return to the previous menu.
Arrow to CONFIGURE MANAGEMENT NETWORK and press ENTER.
If you need a vlan tag set, you may need to reapply it.
Confirm the other settings are correct and press ESC.
Press Y for yes.
Now, you can remove the missing DVSwitch.
If you want to do this via the CLI, then SSH to the host and list the virtual switches on the host:
esxcfg-vswitch -l
Here we see SWITCH1, the vSwitch from the vCenter that had failed. You’ll also notice, that there are no uplinks in SWITCH1, which means we’re clear to delete it. Remember, the switch name is case sensitive!
net-dvs -d SWITCH1
If we list the virtual switches again, we’ll see there’s an error.
To clean that up, we’ll need to run the vsish command with the DvsPortSet listed in the error message.
vsish -e set /net/portsets/DvsPortset-1/destroy destroy
I also ran another esxcfg-vswitch -l to show the switch is completely removed.
Finally, we’ll need to remove the link to the DVS Database, or it’ll come back after rebooting.
rm -f /etc/vmware/dvsdata.db
If you remove the switch via the CLI, then you’ll need to remove the ghost VMKernel NICs that stay around.
esxcli network ip interface remove --interface-name=vmk1
esxcli network ip interface remove --interface-name=vmk2
esxcli network ip interface remove --interface-name=vmk3
esxcli network ip interface remove --interface-name=vmk4
Then, we move on to re-creating the portgroups and VMKernel adapters. As I need to do this to multiple hosts in the cluster, I’m going to SCRIPT IT! I’m going to break this up into sections, and will list the full script at the end.
Lets start with creating the portgroups. I have a total of 5 VMKernel Adapters. 1 for MGMT, 2 for vMotion, and 2 for iSCSI. There’s a 6th for iDRAC, but I’m not creating anything for that just yet. Also, the mgmt portgroup was created automatically when I did the standard switch restore from the DCUI.
############################################################
#
# PowerCLI script to create VMKernel ports on rebuilt hosts
# Created by BLiebowitz on 2/8/2022
#
############################################################
# Get list of VMHosts and assign to variable.
$vmhosts = get-vmhost host1.lab.local # You could also do: Get-Cluster | Get-VMHost to do all hosts in a cluster at once)
foreach ($VMHost in $VMHosts) {
# Check if Portgroups exist, if not then create them.
# Check if the vCenterHA-A Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "VMNetwork-vCenterHA-A") {
Write-Host "vCenterHA-A Network exists" }
else {
New-Virtualportgroup -Name "VMNetwork-vCenterHA-A" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitch0")
Write-Host -foregroundcolor Green "Created VMNetwork-vCenterHA-A" }
# Check if the vCenterHA-B Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "VMNetwork-vCenterHA-B") {
Write-Host "vCenterHA-B Network exists" }
else {
New-Virtualportgroup -Name "VMNetwork-vCenterHA-B" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitch0")
Write-Host -foregroundcolor Green "Created VMNetwork-vCenterHA-B" }
# Check if the iSCSI-A Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "VMKernel-iSCSI-A") {
Write-Host "iSCSI-A Network exists" }
else {
New-Virtualportgroup -Name "VMKernel-iSCSI-A" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitch0")
Write-Host -foregroundcolor Green "Created VMKernel-iSCSI-A"}
# Check if the iSCSI-B Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "VMKernel-iSCSI-B") {
Write-Host "iSCSI-B Network exists" }
else {
New-Virtualportgroup -Name "VMKernel-iSCSI-B" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitch0")
Write-Host -foregroundcolor Green "Created VMKernel-iSCSI-B" }
Now that we have the portgroups created, we can assign IPs and create the VMKernel ports! The script below will prompt for each IP as it goes. I have a document with these IPs and a whole bunch of other great info! Check out my previous post on vDocumentation!
# Check if VMK1 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk1 -erroraction silentlycontinue) {
Write-Host "VMK1 already exists on $vmhost" }
else {
$VMK=New-VMHostNetworkAdapter -PortGroup "VMNetwork-vCenterHA" -VMHost $vmhost -VirtualSwitch (Get-VirtualSwitch vSwitch0) -IP (read-host "What's the VMK1 IP for $vmhost") -SubnetMask 255.255.255.0 -VMotionEnabled:$true
Write-Host -foregroundcolor Green "Created $vmk.name"}
# Check if VMK2 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk2) {
Write-Host "VMK2 already exists on $vmhost" }
else {
New-VMHostNetworkAdapter -PortGroup "VMNetwork-vCenterHA" -VMHost $vmhost -VirtualSwitch (Get-VirtualSwitch vSwitch0) -IP (read-host "What's the VMK2 IP for $vmhost") -SubnetMask 255.255.255.0 -VMotionEnabled:$true }
# Check if VMK3 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk3) {
Write-Host "VMK3 already exists on $vmhost" }
else {
New-VMHostNetworkAdapter -PortGroup "VMKernel-iSCSI-A" -VMHost $vmhost -VirtualSwitch (Get-VirtualSwitch vSwitch0) -IP (read-host "What's the VMK3 IP for $vmhost") -SubnetMask 255.255.255.0 }
# Check if VMK4 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk4) {
Write-Host "VMK4 already exists on $vmhost" }
else {
New-VMHostNetworkAdapter -PortGroup "VMKernel-iSCSI-B" -VMHost $vmhost -VirtualSwitch (Get-VirtualSwitch vSwitch0) -IP (read-host "What's the VMK4 IP for $vmhost") -SubnetMask 255.255.255.0 }
As these are Dell PowerEdge servers, there’s a separate virtual switch and portgroup for them that allows the iDRAC to communicate with ESXi for guest shutdown via iDRAC, etc…
# Check if iDRAC switch exists, if not then create it
if (get-virtualswitch -vmhost $vmhost -name "vSwitchiDRACvusb") {
Write-Host "vSwitchiDRACvusb Switch already exists" }
else {
New-virtualswitch -vmhost $vmhost -Name vSwitchiDRACvusb -nic vusb0 -confirm:$false }
# Check if the iDRAC Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "iDRAC Network") {
Write-Host "iDRAC Network exists" }
else {
New-Virtualportgroup -Name "iDRAC Network" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitchiDRACvusb") }
# Check if VMK5 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk5) {
Write-host "vmk5 already exists on $vmhost" }
else {
New-VMHostNetworkAdapter -PortGroup "iDRAC Network" -VMHost $vmhost -VirtualSwitch (Get-virtualswitch -vmhost $vmhost -name "vSwitchiDRACvusb") -IP "169.254.0.2" -SubnetMask 255.255.255.0 }
# } #Uncomment for more than one host at a time
Now, I can create a new Virtual Distributed Switch. Now, you can create it manually OR, if you’re a good engineer, you’ll have a backup! Check out my previous post that I run once a quarter to backup my vDS configs! Go to the networking tab and right click on the datacenter, go to Distributed Switch, and IMPORT DISTRIBUTED SWITCH.
The script above describing how to backup your vDS configs will have a ZIP file. Point to the ZIP titled vCENTERName_SwitchName.zip. Or, you can use the following PowerShell cmdlet. If you don’t want it to import portgroups, use the -WITHOUTPORTGROUPS switch.
New-VDSwitch -Name "SWITCH1" -BackupPath "c:\MyDistributedSwitchProfile.zip"
Finally, I need to add my hosts to the rebuilt vSwitch, assign uplinks and VMKernel ports!
# Name of vDS the hosts will join.
$vds_name = "SWITCH2"
# Add ESXi host to VDS
Write-Host "Adding" $vmhost "to" $vds_name
Get-VDSwitch -Name $vds_name | Add-VDSwitchVMHost -VMHost $vmhost -Confirm:$false
Write-Host -ForegroundColor Green "Added $vmhost to $vds_name"
# Migrate pNIC to VDS (vmnic0)
Write-Host "Adding vmnic0/vmnic1 to" $vds_name
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false
Write-Host -ForegroundColor Green "Added vmnic0 to" $vds_name
# Migrate VMkernel interfaces to VDS
# Management #
$mgmt_portgroup = "VMNetwork-MGMT"
Write-Host "Migrating" $mgmt_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $mgmt_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk0 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null
# vMotion 1#
$vmotion_portgroup = "VMNetwork-vCenterHA"
Write-Host "Migrating" $vmotion_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $vmotion_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk1 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null
# vMotion 2#
$vmotion_portgroup = "VMNetwork-vCenterHA"
Write-Host "Migrating" $vmotion_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $vmotion_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk2 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null
# Storage 1#
$storage_portgroup = "VMKernel-iSCSI-A"
Write-Host "Migrating" $storage_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $storage_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk3 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null
# Storage 2#
$storage_portgroup = "VMKernel-iSCSI-B"
Write-Host "Migrating" $storage_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $storage_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk4 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false | Out-Null
# Migrate pNIC to VDS (vmnic1)
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic1
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false
# Cleanup Portgroups
Write-host "Cleaning up portgroups from the standard switch"
$vSwitch_name = "vSwitch0"
Get-virtualswitch -Name $vSwitch_name -VMHost $vmhost | get-virtualportgroup | Remove-VirtualPortGroup -confirm:$false
# Remove vSwitch0
Write-Host "Removing" $vSwitch_name
Get-VirtualSwitch -Name $vSwitch_name -VMHost $vmhost | Remove-VirtualSwitch -confirm:$false
}
Here’s the script in it’s entirety.
############################################################
#
# PowerCLI script to create VMKernel ports on rebuilt hosts
# Created by BLiebowitz on 12/28/2022
#
############################################################
# Get list of VMHosts and assign to variable
$vmhosts = get-vmhost host01.homelab.local # You could do multiple hosts here separated by commas. Or do an entire cluster: Get-Cluster LAB | Get-VMHost
# Create a loop to run code on each host)
foreach ($vmhost in $vmhosts) {
# Put the host into Maintenance Mode
Get-VMHost $vmhost | Set-VMHost -State Maintenance -Evacuate:$true -Confirm:$false
# Check if Portgroups exist, if not then create them.
# Local vSwitch Name
$vswitch = get-virtualswitch -VMHost $vmhost | Where {$_.Name -notmatch "idrac"} | Sort Name | Select -Last 1 # I did this because if there's already a standard switch and you migrate back via the DCUI, it'll create vSwitch1.
# Check if the vCenterHA Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -virtualswitch $vswitch -Name "VMNetwork-vCenterHA_A" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "vCenterHA_A Network exists" } else {
New-Virtualportgroup -Name "VMNetwork-vCenterHA_A" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name $vswitch)
Write-Host -ForegroundColor Green "Created Portgroup VMNetwork-vCenterHA-A" }
# Check if the vCenterHA Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -virtualswitch $vswitch -Name "VMNetwork-vCenterHA_B" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "vCenterHA_B Network exists" } else {
New-Virtualportgroup -Name "VMNetwork-vCenterHA_B" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name $vswitch)
Write-Host -ForegroundColor Green "Created Portgroup VMNetwork-vCenterHA-B" }
# Check if the iSCSI-A Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -virtualswitch $vswitch -Name "VMKernel-iSCSI-A" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "iSCSI-A Network exists" } else {
New-Virtualportgroup -Name "VMKernel-iSCSI-A" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name $vswitch)
Write-Host -ForegroundColor Green "Created Portgroup VMKernel-iSCSI-A" }
# Check if the iSCSI-B Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -virtualswitch $vswitch -Name "VMKernel-iSCSI-B" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "iSCSI-B Network exists" } else {
New-Virtualportgroup -Name "VMKernel-iSCSI-B" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name $vswitch)
Write-Host -ForegroundColor Green "Created Portgroup VMKernel-iSCSI-B" }
# Check if VMK1 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk1 -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "VMK1 already exists on $vmhost"
} else {
$VMK1 = New-VMHostNetworkAdapter -PortGroup "VMNetwork-vCenterHA_A" -VMHost $vmhost -VirtualSwitch (get-vmhost $vmhost | get-virtualswitch -name $vswitch) -IP (read-host "What's the VMK1 IP for $vmhost") -SubnetMask 255.255.255.0 -VMotionEnabled:$true
$VMK = $vmk1.DeviceName
write-host -ForegroundColor Green "Created $VMK" }
# Check if VMK2 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk2 -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "VMK2 already exists on $vmhost"
} else {
$VMK2 = New-VMHostNetworkAdapter -PortGroup "VMNetwork-vCenterHA_B" -VMHost $vmhost -VirtualSwitch (get-vmhost $vmhost | get-virtualswitch -name $vswitch) -IP (read-host "What's the VMK2 IP for $vmhost") -SubnetMask 255.255.255.0 -VMotionEnabled:$true
$VMK = $vmk2.DeviceName
write-host -ForegroundColor Green "Created $VMK" }
# Check if VMK3 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk3 -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "VMK3 already exists on $vmhost"
} else {
$VMK3 = New-VMHostNetworkAdapter -PortGroup "VMKernel-iSCSI-A" -VMHost $vmhost -VirtualSwitch (get-vmhost $vmhost | get-virtualswitch -name $vswitch) -IP (read-host "What's the VMK3 IP for $vmhost") -SubnetMask 255.255.255.0
$VMK = $VMK3.DeviceName
write-host -ForegroundColor Green "Created $VMK" }
# Check if VMK4 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk4 -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "VMK4 already exists on $vmhost"
} else {
$VMK4 = New-VMHostNetworkAdapter -PortGroup "VMKernel-iSCSI-B" -VMHost $vmhost -VirtualSwitch (get-vmhost $vmhost | get-virtualswitch -name $vswitch) -IP (read-host "What's the VMK4 IP for $vmhost") -SubnetMask 255.255.255.0
$VMK = $VMK4.DeviceName
write-host -ForegroundColor Green "Created $VMK" }
# Check if iDRAC switch exists, if not then create it
if (get-virtualswitch -vmhost $vmhost -name "vSwitchiDRACvusb" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "vSwitchiDRACvusb Switch already exists" } else {
New-virtualswitch -vmhost $vmhost -Name vSwitchiDRACvusb -nic vusb0 -confirm:$false
write-host -ForegroundColor Green "Created vSwitchDRACvusb" }
# Check if the iDRAC Portgroup exists, if not then create it
if (get-virtualportgroup -vmhost $vmhost -Name "iDRAC Network" -erroraction SilentlyContinue) {
Write-Host -ForegroundColor Yellow "iDRAC Network exists"
} else {
New-Virtualportgroup -Name "iDRAC Network" -VirtualSwitch (get-virtualswitch -vmhost $vmhost -Name "vSwitchiDRACvusb")
write-host -ForegroundColor Green "Created Portgroup: iDRAC Network" }
# Check if VMK5 exists, if not then create it.
if (Get-vmhostnetworkadapter -vmhost $vmhost -vmkernel -name vmk5 -erroraction SilentlyContinue) {
Write-host -ForegroundColor Yellow "vmk5 already exists on $vmhost" } else {
$VMK5 = New-VMHostNetworkAdapter -PortGroup "iDRAC Network" -VMHost $vmhost -VirtualSwitch (Get-virtualswitch -vmhost $vmhost -name "vSwitchiDRACvusb") -IP "169.254.0.2" -SubnetMask 255.255.255.0
$VMK = $VMK5.DeviceName
write-host -ForegroundColor Green "Created $VMK"}
# Name of vDS the hosts will join.
$vds_name = "dvSwitch"
# Add ESXi host to VDS
Write-Host -ForegroundColor Cyan "Adding" $vmhost "to" $vds_name
Get-VDSwitch -Name $vds_name | Add-VDSwitchVMHost -VMHost $vmhost -Confirm:$false
Write-Host -ForegroundColor Green "Added $vmhost to $vds_name"
# Migrate pNIC to VDS (vmnic0)
Write-Host -ForegroundColor Cyan "Adding vmnic0/vmnic1 to" $vds_name
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic0
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false
Write-Host -ForegroundColor Green "Added vmnic0 to" $vds_name
# Migrate VMkernel interfaces to VDS
# Management #
$mgmt_portgroup = "VMNetwork-MGMT"
Write-Host -ForegroundColor Cyan "Migrating" $mgmt_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $mgmt_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name vmk0 -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false
Write-Host -ForegroundColor Green "Moved $mgmt_portgroup to $vds_name"
# vMotion 1#
$vmotion_portgroup = "VMNetwork-vCenterHA"
Write-Host -ForegroundColor Cyan "Migrating" $vmotion_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $vmotion_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name $vmk1.name -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false
Write-Host -ForegroundColor Green "Moved $vMotion_portgroup to $vds_name"
# vMotion 2#
$vmotion_portgroup = "VMNetwork-vCenterHA"
Write-Host -ForegroundColor Cyan "Migrating" $vmotion_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $vmotion_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name $vmk2.name -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false
Write-Host -ForegroundColor Green "Moved $vMotion_portgroup to $vds_name"
# Storage 1#
$storage_portgroup = "VMKernel-iSCSI-A"
Write-Host -ForegroundColor Cyan "Migrating" $storage_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $storage_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name $vmk3.name -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false
Write-Host -ForegroundColor Green "Moved $Storage_portgroup to $vds_name"
# Storage 2#
$storage_portgroup = "VMKernel-iSCSI-B"
Write-Host -ForegroundColor Cyan "Migrating" $storage_portgroup "to" $vds_name
$dvportgroup = Get-VDPortgroup -name $storage_portgroup -VDSwitch $vds
$vmk = Get-VMHostNetworkAdapter -Name $vmk4.name -VMHost $vmhost
Set-VMHostNetworkAdapter -PortGroup $dvportgroup -VirtualNic $vmk -confirm:$false
Write-Host -ForegroundColor Green "Moved $Storage_portgroup to $vds_name"
# Migrate pNIC to VDS (vmnic1)
Write-host -ForegroundColor Cyan "Migrating VMnic1 to $vds_name"
$vmhostNetworkAdapter = Get-VMHost $vmhost | Get-VMHostNetworkAdapter -Physical -Name vmnic1
$vds | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $vmhostNetworkAdapter -Confirm:$false
Write-Host -ForegroundColor Green "Migrated vmnic1 to $vds_name"
# Cleanup Portgroups
Write-host -ForegroundColor Cyan "Cleaning up portgroups from the standard switch"
Get-virtualswitch -Name $vSwitch -VMHost $vmhost | get-virtualportgroup | Remove-VirtualPortGroup -confirm:$false
Write-Host -ForegroundColor Green "Removed Portgroups from $vswitch"
# Remove vSwitch0
Write-Host -ForegroundColor Cyan "Removing" $vSwitch
Get-VirtualSwitch -Name $vSwitch -VMHost $vmhost | Remove-VirtualSwitch -confirm:$false
Write-Host -ForegroundColor Green "Removed from $vswitch"
}
Ben Liebowitz, VCP, vExpert
NJ VMUG Leader