VMware Cloud Community
TryllZ
Expert
Expert
Jump to solution

Creating Distributed Switch and Migrating Management Network..

Hi,

I'm creating the following in Workstation, and am unable to understand how to go about it.

The following script adds hosts to the vCenter, then a Distributed Switch is created and hosts added to it, then Portgroups added to the Distributed Switch. Now only 2 things remain, the vmnics, and vmkernels which is what I'm not understanding. When I do them using GUI they work fine and transfer successfully but how to achieve the same via PowerCLI. The problem is when I try to add vmnic0 (management vmnic) the connection is lost, I have tested the script without vmnic0 and it works fine.

CSV File Content

Hosts,Cluster,NIC,PortGroup,VMK,IP

esxi21.v.lab,vSAN_Cluster,vmnic0,ManagementPG,ManagementNetwork,192.168.2.21

esxi22.v.lab,vSAN_Cluster,vmnic0,ManagementPG,ManagementNetwork,192.168.2.22

esxi23.v.lab,vSAN_Cluster,vmnic0,ManagementPG,ManagementNetwork,192.168.2.23

esxi24.v.lab,iSCSI_Cluster,vmnic0,ManagementPG,ManagementNetwork,192.168.2.34

esxi25.v.lab,iSCSI_Cluster,vmnic0,ManagementPG,ManagementNetwork,192.168.2.25

esxi21.v.lab,vSAN_Cluster,vmnic1,ManagementPG,ManagementNetwork2,192.168.2.31

esxi22.v.lab,vSAN_Cluster,vmnic1,ManagementPG,ManagementNetwork2,192.168.2.32

esxi23.v.lab,vSAN_Cluster,vmnic1,ManagementPG,ManagementNetwork2,192.168.2.33

esxi24.v.lab,iSCSI_Cluster,vmnic1,ManagementPG,ManagementNetwork2,192.168.2.34

esxi25.v.lab,iSCSI_Cluster,vmnic1,ManagementPG,ManagementNetwork2,192.168.2.35

esxi21.v.lab,vSAN_Cluster,vmnic2,NFSPG,NFS,192.168.3.21

esxi22.v.lab,vSAN_Cluster,vmnic2,NFSPG,NFS,192.168.3.22

esxi23.v.lab,vSAN_Cluster,vmnic2,NFSPG,NFS,192.168.3.23

esxi24.v.lab,iSCSI_Cluster,vmnic2,NFSPG,NFS,192.168.3.24

esxi25.v.lab,iSCSI_Cluster,vmnic2,NFSPG,NFS,192.168.3.25

esxi21.v.lab,vSAN_Cluster,vmnic3,vSANPG,vSAN,192.168.5.21

esxi22.v.lab,vSAN_Cluster,vmnic3,vSANPG,vSAN,192.168.5.22

esxi23.v.lab,vSAN_Cluster,vmnic3,vSANPG,vSAN,192.168.5.23

esxi24.v.lab,iSCSI_Cluster,vmnic3,iSCSI1PG,iSCSI1,192.168.4.24

esxi25.v.lab,iSCSI_Cluster,vmnic3,iSCSI1PG,iSCSI1,192.168.4.25

esxi21.v.lab,vSAN_Cluster,vmnic4,vSANPG,vSAN,192.168.5.31

esxi22.v.lab,vSAN_Cluster,vmnic4,vSANPG,vSAN,192.168.5.32

esxi23.v.lab,vSAN_Cluster,vmnic4,vSANPG,vSAN,192.168.5.33

esxi24.v.lab,iSCSI_Cluster,vmnic4,iSCSI2PG,iSCSI2,192.168.4.34

esxi25.v.lab,iSCSI_Cluster,vmnic4,iSCSI2PG,iSCSI2,192.168.4.35

esxi21.v.lab,vSAN_Cluster,vmnic5,vMotionPG,vMotion,192.168.6.21

esxi22.v.lab,vSAN_Cluster,vmnic5,vMotionPG,vMotion,192.168.6.22

esxi23.v.lab,vSAN_Cluster,vmnic5,vMotionPG,vMotion,192.168.6.23

esxi21.v.lab,vSAN_Cluster,vmnic6,vMotionPG,vMotion,192.168.6.31

esxi22.v.lab,vSAN_Cluster,vmnic6,vMotionPG,vMotion,192.168.6.32

esxi23.v.lab,vSAN_Cluster,vmnic6,vMotionPG,vMotion,192.168.6.33

esxi21.v.lab,vSAN_Cluster,vmnic7,FT,FT,192.168.7.21

esxi22.v.lab,vSAN_Cluster,vmnic7,FT,FT,192.168.7.22

esxi23.v.lab,vSAN_Cluster,vmnic7,FT,FT,192.168.7.23

esxi21.v.lab,vSAN_Cluster,vmnic8,FT,FT,192.168.7.31

esxi22.v.lab,vSAN_Cluster,vmnic8,FT,FT,192.168.7.32

esxi23.v.lab,vSAN_Cluster,vmnic8,FT,FT,192.168.7.33

PowerCLI Script

$csvFile = Import-CSV -Path C:\Users\Administrator\Desktop\esxiHostsdvSwitch.csv

Connect-VIServer vcsa.v.lab -Force

Set-PowerCLIConfiguration -Scope User -ParticipateInCEIP $false -confirm:$false

$dc = New-Datacenter -location (Get-Folder -NoRecursion) -Name vDatacenter

New-Cluster -Name iSCSI_Cluster -Location $dc

New-Cluster -Name vSAN_Cluster -Location $dc

$dvSwitch = "vDCSwitch"

New-VDSwitch -Name $dvSwitch -Location vDatacenter -NumUplinkPorts 9 -MaxPorts 256 -Version "6.6.0"

foreach ($val in $csvFile)

   {

      $esxiHosts = $val.Hosts

      $clusterName = $val.Cluster

      $nic = $val.NIC

      $pgroup = $val.PortGroup

      $ip = $val.IP

      Add-VMHost $esxiHosts -User root -Password "" -Location $clusterName -Force

      Add-VDSwitchVMHost -VMHost $esxiHosts -VDSwitch $dvSwitch

      New-VDPortgroup -Name $pgroup -VDSwitch $dvSwitch -NumPorts 8

   }

foreach ($val in $csvFile)

   {

      $esxiHosts = $val.Hosts

      $nic = $val.NIC

      $dSwitch = Get-VMHost $esxiHosts | Get-VMHostNetworkAdapter -Physical -Name $nic

      Get-VDSwitch $dvSwitch | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $dSwitch -Confirm:$false

}

Thank You

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

When you use the Add-VDSwitchPhysicalNetworkAdapter, the VMKernel is migrated.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
5 Replies
TryllZ
Expert
Expert
Jump to solution

Also the VMKernels, how do I migrate the Management VMKernel, I'm not asking the script for it, I'm asking if the VMKernel is migrated along with the vmnics, before the vmnics or after..

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

When you use the Add-VDSwitchPhysicalNetworkAdapter, the VMKernel is migrated.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Hi LucD,

Thanks as always, I'm unsure how you got that link because when I searched I only got Add-VDSwitchPhysicalNetworkAdapter link without any VirtualNIC examples..?!

Thanks again..

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

They don't update the links for the online help when there is a PowerCLI upgrade.

They create a new link :smileyangry:

I raised an Idea to change that.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
TryllZ
Expert
Expert
Jump to solution

Thanks LucD..

Reply
0 Kudos