Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Moving connected physical nics and vmk's on ESXi host to DVS/VDS.
You can target a single host or set of hosts. Made to only move 'management' vmk's.
Idea is that you would create vmotion, vsan, etc. vmk's after on VDS/DVS
$VMhost = Get-VMHost "NameofHost"
If you haven't created a vDSwitch yet, you can do so by replacing get-vdswitch with New-VDSwitch
$TargetVDS = New-VDSwitch -Name -Location (get-datacenter "nameofvirtualdatacenter")
$TargetPG = New-VDPortgroup -vdswitch $TargetVDS -Name "Whatevernameyouwant" -VLANID <# Replace if applicable #>
$TargetVDS = Get-VDSwitch "NameofVDSwitch"
$TargetPG = Get-VDPortgroup "NameofManagementPortGroup"
# This will grab all physical/virtual adapters w/ connectivity.
$NetAdapters = $VMHost | Get-VMHostNetworkAdapter | Where-Object {$_.bitrateperSec -ne 0}
# Filter for physical nics
$PhysicalNet = $NetAdapters | Where-Object {$_.Name -match "vmnic"}
# Filter for vmkernel adapters
$VMKNet = $NetAdapters | Where-Object {$_.Name -match "vmk"}
# Adds host to VDS/DVS if not done so already.
Add-VDSwitchVMhost -VDSwitch $TargetVDS -VMHost $VMHost
# Migrates all adapters vmk/vmnic to VDS. (Assumes portfast enabled on switch)
# If not, below will need rewrite to move one physical adapter at a time w/ sleep/while statement
Add-VDSwitchPhysicalNetworkAdapter -VMHostPhysicalNic $PhysicalNet -DistributedSwitch $TargetVDS -VMHostVirtualNic $VMKNet -VirtualNicPortgroup $TargetPG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.