6 Replies Latest reply on Sep 25, 2020 6:42 AM by MC1903

    Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12

    MC1903 Enthusiast

      Question for LucD,

       

      What is the latest/preferred way to migrate a vSphere 7 host from a vSS to a vDS with PowerCLI v12?

       

      Adding the host to the vDS (using 'Add-VDSwitchVMHost') works, but then it gets disconnected trying to migrate vmnics0 & 1 (using 'Add-VDSwitchPhysicalNetworkAdapter') and the management vmk0 (using 'Set-VMHostNetworkAdapter')?.

       

      I think it is a timing issue, as I am executing the commands in sequence and not all at once. I would post my test script, but it is right 'dogs breakfast'

       

      I am 99.5% confident that it is not an underlying network issue (it is a nested lab), as it successfully migrates using the vCenter Server vDS 'Add and Manage Hosts' wizard.

       

      Any advice/pointers will be greatly appreciated.

       

      Thanks in advance,

      M

        • 1. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
          LucD Guru
          User ModeratorsCommunity WarriorsvExpert

          Since you have 2 pNICs you will have to migrate just one of them to start with (using the Add-VDSwitchPhysicalNetworkAdapter).

          Then you have connectivity on both the VSS and the VDS.

          Now you could migrate your VMKernel interfaces and portgroups.

          When all is migrated, migrate the remaining pNIC.

           

          This is also how the wizard does this afaik.

          You could check by using CodeCapture.

           

          William posted a script that does a VSS to VDS migration, see Automate the migration from Virtual Standard Switch to vSphere Distributed Switch using PowerCLI 5.5

          Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
          • 2. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
            MC1903 Enthusiast

            Hi LucD

             

            Thank you. I *think* have tried doing just that.

             

            Would you mind having a look through my test code? Is my approach/logic wrong, is it just timing?

             

            PowerShell version is 5.1

            PowerCLI version is 12.0.0 build 15947286

             

            My Test Code

            Remove-Variable -Name * -ErrorAction SilentlyContinue

            Clear-Host

             

             

            #vCenter Credentials

            $VIServer = "mc-vcsa-v-201a.momusconsulting.com"

            $VIUsername = 'administrator@vsphere.local'

            $VIPassword = 'Pa55word5!'

             

             

            $vCenter = Connect-VIServer $VIServer -User $VIUsername -Password $VIPassword -WarningAction SilentlyContinue -ErrorAction Stop

             

            $VMHosts = Get-VMHost -Server $vCenter | Where-Object {$_.Name -match 'mc-esxi-v-205a.momusconsulting.com'} #'Where' is to limit the scope during testing

            $VDSwitchName = "vDS1-Management-A"

            $Mgmt_PortGroup = "VLAN0101_Management"

            $Mgmt_vmk = "vmk0"

             

             

            #Migrate Host Management from vSwitch0 to vDS1-Management

            ForEach ($VMHost in $VMHosts) {

            $VDSwitch = Get-VDSwitch -Server $vCenter -Name $VDSwitchName

            $VDSwitch_PortGroup = Get-VDPortgroup -name $Mgmt_PortGroup -VDSwitch $VDSwitch

            $VMK = Get-VMHostNetworkAdapter -Name $Mgmt_vmk -VMHost $VMHost

             

             

            #Add the ESXi host to the vDS

            Write-Host "Adding" $VMHost "to" $VDSwitch

            $VDSwitch | Add-VDSwitchVMHost -VMHost $VMHost

             

             

            #Migrate unused pNIC vmnic1 to vDS

            Write-Host "Adding vmnic1 to" $VDSwitchName

            $VMNIC1 = Get-VMHost $VMHost | Get-VMHostNetworkAdapter -Physical -Name vmnic1

            $VDSwitch | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $VMNIC1 -Confirm:$false -WarningAction SilentlyContinue -ErrorAction Stop

             

             

            #Migrate the Management VMkernel interface to vDS1-Management

            Write-Host "Migrating vmk0 to" $VDSwitchName $VDSwitchMgmt_PortGroup

            Set-VMHostNetworkAdapter -PortGroup $VDSwitch_PortGroup -VirtualNic $VMK -confirm:$false -WarningAction SilentlyContinue -ErrorAction Stop

             

             

             

            #Migrate pNIC vmnic0 from vSS to vDS

            Write-Host "Adding vmnic0 to" $VDSwitchName

            $VMNIC0 = Get-VMHost $VMHost | Get-VMHostNetworkAdapter -Physical -Name vmnic0

            $VDSwitch | Add-VDSwitchPhysicalNetworkAdapter -VMHostNetworkAdapter $VMNIC0 -Confirm:$false -WarningAction SilentlyContinue -ErrorAction Stop

             

             

            }

             

             

            Script Output & Error

            Adding mc-esxi-v-205a.momusconsulting.com to vDS1-Management-A

            Adding vmnic1 to vDS1-Management-A

            Migrating vmk0 to vDS1-Management-A

            Set-VMHostNetworkAdapter : 24/09/2020 14:24:17    Set-VMHostNetworkAdapter        An error occurred while communicating with the remote host. Network configuration change disconnected the host

            'mc-esxi-v-205a.momusconsulting.com' from vCenter server and has been rolled back.   

            At P:\Momus Lab\Testing\Nested Vcenter add hosts to vds v2a - vmtn.ps1:32 char:1

            + Set-VMHostNetworkAdapter -PortGroup $VDSwitch_PortGroup -VirtualNic $ ...

            + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

                + CategoryInfo          : NotSpecified: (:) [Set-VMHostNetworkAdapter], HostCommunication

                + FullyQualifiedErrorId : Client20_VirtualNetworkServiceImpl_AddVMHostNetworkAdapter_VIError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Host.SetVMHostNetworkAdapter

             

             

            PS C:\Users\Administrator>

             

             

             

            The vCenter  'Code Capture' of the manual UI migration just makes my head spin:

             

            Code Capture

            #----------------- Start of code capture -----------------

             

            #---------------QueryAvailableDvsSpec---------------

            $recommended = $true

            $_this = Get-View -Id 'DistributedVirtualSwitchManager-DVSManager'

            $_this.QueryAvailableDvsSpec($recommended)

             

            #---------------QueryAvailableDvsSpec---------------

            $recommended = $true

            $_this = Get-View -Id 'DistributedVirtualSwitchManager-DVSManager'

            $_this.QueryAvailableDvsSpec($recommended)

             

            #---------------QueryDvsCheckCompatibility---------------

            $hostContainer = New-Object VMware.Vim.DistributedVirtualSwitchManagerHostContainer

            $hostContainer.Container = New-Object VMware.Vim.ManagedObjectReference

            $hostContainer.Container.Type = 'Datacenter'

            $hostContainer.Container.Value = 'datacenter-2251'

            $hostContainer.Recursive = $true

            $dvsProductSpec = New-Object VMware.Vim.DistributedVirtualSwitchManagerDvsProductSpec

            $dvsProductSpec.NewSwitchProductSpec = New-Object VMware.Vim.DistributedVirtualSwitchProductSpec

            $dvsProductSpec.NewSwitchProductSpec.ForwardingClass = 'cswitch'

            $dvsProductSpec.NewSwitchProductSpec.Build = '00000'

            $dvsProductSpec.NewSwitchProductSpec.Vendor = 'VMware, Inc.'

            $dvsProductSpec.NewSwitchProductSpec.Name = 'DVS'

            $dvsProductSpec.NewSwitchProductSpec.Version = '7.0.0'

            $hostFilterSpec = New-Object VMware.Vim.DistributedVirtualSwitchManagerHostDvsFilterSpec[] (1)

            $hostFilterSpec[0] = New-Object VMware.Vim.DistributedVirtualSwitchManagerHostContainerFilter

            $hostFilterSpec[0].HostContainer = New-Object VMware.Vim.DistributedVirtualSwitchManagerHostContainer

            $hostFilterSpec[0].HostContainer.Container = New-Object VMware.Vim.ManagedObjectReference

            $hostFilterSpec[0].HostContainer.Container.Type = 'Datacenter'

            $hostFilterSpec[0].HostContainer.Container.Value = 'datacenter-2251'

            $hostFilterSpec[0].HostContainer.Recursive = $true

            $hostFilterSpec[0].Inclusive = $true

            $_this = Get-View -Id 'DistributedVirtualSwitchManager-DVSManager'

            $_this.QueryDvsCheckCompatibility($hostContainer, $dvsProductSpec, $hostFilterSpec)

             

            #---------------QueryCompatibleHostForExistingDvs---------------

            $container = New-Object VMware.Vim.ManagedObjectReference

            $container.Type = 'Datacenter'

            $container.Value = 'datacenter-2251'

            $recursive = $true

            $dvs = New-Object VMware.Vim.ManagedObjectReference

            $dvs.Type = 'VmwareDistributedVirtualSwitch'

            $dvs.Value = 'dvs-2267'

            $_this = Get-View -Id 'DistributedVirtualSwitchManager-DVSManager'

            $_this.QueryCompatibleHostForExistingDvs($container, $recursive, $dvs)

             

            #---------------ReconfigureDvs_Task---------------

            $spec = New-Object VMware.Vim.DVSConfigSpec

            $spec.ConfigVersion = '17'

            $spec.Host = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberConfigSpec[] (1)

            $spec.Host[0] = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberConfigSpec

            $spec.Host[0].Host = New-Object VMware.Vim.ManagedObjectReference

            $spec.Host[0].Host.Type = 'HostSystem'

            $spec.Host[0].Host.Value = 'host-2264'

            $spec.Host[0].Operation = 'add'

            $_this = Get-View -Id 'VmwareDistributedVirtualSwitch-dvs-2267'

            $_this.ReconfigureDvs_Task($spec)

             

            #---------------FetchDVPorts---------------

            $criteria = New-Object VMware.Vim.DistributedVirtualSwitchPortCriteria

            $criteria.UplinkPort = $true

            $_this = Get-View -Id 'VmwareDistributedVirtualSwitch-dvs-2267'

            $_this.FetchDVPorts($criteria)

             

            #---------------UpdateNetworkConfig---------------

            $config = New-Object VMware.Vim.HostNetworkConfig

            $config.Vswitch = New-Object VMware.Vim.HostVirtualSwitchConfig[] (1)

            $config.Vswitch[0] = New-Object VMware.Vim.HostVirtualSwitchConfig

            $config.Vswitch[0].Name = 'vSwitch0'

            $config.Vswitch[0].ChangeOperation = 'edit'

            $config.Vswitch[0].Spec = New-Object VMware.Vim.HostVirtualSwitchSpec

            $config.Vswitch[0].Spec.NumPorts = 128

            $config.Vswitch[0].Spec.Policy = New-Object VMware.Vim.HostNetworkPolicy

            $config.Vswitch[0].Spec.Policy.Security = New-Object VMware.Vim.HostNetworkSecurityPolicy

            $config.Vswitch[0].Spec.Policy.Security.AllowPromiscuous = $false

            $config.Vswitch[0].Spec.Policy.Security.ForgedTransmits = $false

            $config.Vswitch[0].Spec.Policy.Security.MacChanges = $false

            $config.Vswitch[0].Spec.Policy.OffloadPolicy = New-Object VMware.Vim.HostNetOffloadCapabilities

            $config.Vswitch[0].Spec.Policy.OffloadPolicy.TcpSegmentation = $true

            $config.Vswitch[0].Spec.Policy.OffloadPolicy.ZeroCopyXmit = $true

            $config.Vswitch[0].Spec.Policy.OffloadPolicy.CsumOffload = $true

            $config.Vswitch[0].Spec.Policy.ShapingPolicy = New-Object VMware.Vim.HostNetworkTrafficShapingPolicy

            $config.Vswitch[0].Spec.Policy.ShapingPolicy.Enabled = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming = New-Object VMware.Vim.HostNicTeamingPolicy

            $config.Vswitch[0].Spec.Policy.NicTeaming.NotifySwitches = $true

            $config.Vswitch[0].Spec.Policy.NicTeaming.RollingOrder = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria = New-Object VMware.Vim.HostNicFailureCriteria

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.FullDuplex = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.Percentage = 0

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.CheckErrorPercent = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.CheckDuplex = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.CheckBeacon = $false

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.Speed = 10

            $config.Vswitch[0].Spec.Policy.NicTeaming.FailureCriteria.CheckSpeed = 'minimum'

            $config.Vswitch[0].Spec.Policy.NicTeaming.Policy = 'loadbalance_srcid'

            $config.Vswitch[0].Spec.Policy.NicTeaming.ReversePolicy = $true

            $config.Portgroup = New-Object VMware.Vim.HostPortGroupConfig[] (1)

            $config.Portgroup[0] = New-Object VMware.Vim.HostPortGroupConfig

            $config.Portgroup[0].ChangeOperation = 'remove'

            $config.Portgroup[0].Spec = New-Object VMware.Vim.HostPortGroupSpec

            $config.Portgroup[0].Spec.VswitchName = ''

            $config.Portgroup[0].Spec.VlanId = -1

            $config.Portgroup[0].Spec.Name = 'Management Network'

            $config.Portgroup[0].Spec.Policy = New-Object VMware.Vim.HostNetworkPolicy

            $config.Vnic = New-Object VMware.Vim.HostVirtualNicConfig[] (1)

            $config.Vnic[0] = New-Object VMware.Vim.HostVirtualNicConfig

            $config.Vnic[0].Portgroup = ''

            $config.Vnic[0].Device = 'vmk0'

            $config.Vnic[0].ChangeOperation = 'edit'

            $config.Vnic[0].Spec = New-Object VMware.Vim.HostVirtualNicSpec

            $config.Vnic[0].Spec.DistributedVirtualPort = New-Object VMware.Vim.DistributedVirtualSwitchPortConnection

            $config.Vnic[0].Spec.DistributedVirtualPort.SwitchUuid = '50 09 85 33 ea 23 be 5e-58 75 9f 7d 98 09 ef 73'

            $config.Vnic[0].Spec.DistributedVirtualPort.PortgroupKey = 'dvportgroup-2269'

            $config.ProxySwitch = New-Object VMware.Vim.HostProxySwitchConfig[] (1)

            $config.ProxySwitch[0] = New-Object VMware.Vim.HostProxySwitchConfig

            $config.ProxySwitch[0].Uuid = '50 09 85 33 ea 23 be 5e-58 75 9f 7d 98 09 ef 73'

            $config.ProxySwitch[0].ChangeOperation = 'edit'

            $config.ProxySwitch[0].Spec = New-Object VMware.Vim.HostProxySwitchSpec

            $config.ProxySwitch[0].Spec.Backing = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicBacking

            $config.ProxySwitch[0].Spec.Backing.PnicSpec = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec[] (2)

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[0] = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[0].PnicDevice = 'vmnic0'

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[0].UplinkPortKey = '390'

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[0].UplinkPortgroupKey = 'dvportgroup-2268'

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[1] = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberPnicSpec

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[1].PnicDevice = 'vmnic1'

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[1].UplinkPortKey = '391'

            $config.ProxySwitch[0].Spec.Backing.PnicSpec[1].UplinkPortgroupKey = 'dvportgroup-2268'

            $changeMode = 'modify'

            $_this = Get-View -Id 'HostNetworkSystem-networkSystem-2264'

            $_this.UpdateNetworkConfig($config, $changeMode)

             

            #---------------QueryAvailableDvsSpec---------------

            $recommended = $true

            $_this = Get-View -Id 'DistributedVirtualSwitchManager-DVSManager'

            $_this.QueryAvailableDvsSpec($recommended)

             

             

            #----------------- End of code capture -----------------

             

             

            Apprecaite your help

            M

            • 3. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
              LucD Guru
              Community WarriorsvExpertUser Moderators

              Did you already try by first adding the 'unused' vmnic1 to the VSS as active NIC?
              Are you sure vmnic1 maps to the same VLANs as vmnic0?

               

              With the API call, the UpdateNetworkConfig takes care there is interruption (same as the Web client).

              Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
              • 4. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
                MC1903 Enthusiast

                Hi LucD

                 

                I had tried adding the unused vmnic1 onto the vSS first, still fails.

                 

                The underlying networking for the nested host vmnic0 & vmnic1 are VLAN trunks; with the same VLANs from the physical switch.

                 

                I think it is a quirk of my nested lab and/or the execution time of the 4 PowerCLI commands, as the UI vDS Add Hosts wizard completes the whole migration in 1 second (with 1 lost PING) starting from just vmnic0 being connected to vSwitch0/vmk0 PG.

                 

                Is it possible to interact with the UpdateNetworkConfig API call directly? Would you have a example? Could I send all of the changes in one hit? #graspingatstraws

                 

                How can I use the Code Capture?

                 

                Thanks for your help,

                M

                • 5. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
                  LucD Guru
                  Community WarriorsvExpertUser Moderators

                  CodeCapture gives you all the API calls that happen when a specific action in the Web client are done.

                  There are often calls that are not really needed in a script.

                  These mostly concern retrieving the data that is shown in the Web client, or validation checks.

                   

                  In fact, there in that CodeCapture only API calls that are really needed for the VSS -> VDS migration.

                   

                  1) Add the ESXi node to the VDS (which is in fact what Add-VSSwitchVMHost is doing)

                   

                  $spec = New-Object VMware.Vim.DVSConfigSpec

                  $spec.ConfigVersion = '17'

                  $spec.Host = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberConfigSpec[] (1)

                  $spec.Host[0] = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberConfigSpec

                  $spec.Host[0].Host = New-Object VMware.Vim.ManagedObjectReference

                  $spec.Host[0].Host.Type = 'HostSystem'

                  $spec.Host[0].Host.Value = 'host-2264'

                  $spec.Host[0].Operation = 'add'

                  $_this = Get-View -Id 'VmwareDistributedVirtualSwitch-dvs-2267'

                  $_this.ReconfigureDvs_Task($spec)

                   

                  2) A series of actions to migrate from VSS to VDS

                   

                  - remove the pNICs from the VSS (the $config.Vswitch part)

                  - remove the portroup on the VSS ($config.Portgroup)

                  - reconfigure the vmkernel on the VDS ($config.Vnic)

                  - add the pNICs on the VDS ($config.ProxySwitch)

                   

                  I assume that the UpdateNetworkConfig method 'knows' how to do this without the caller suffering an connection issue.

                  A general remark on code from CodeCapture is that is code for 1 specific host (host-2264) and 1 specific VSS and VDS (dvportgroup-2268).

                  So you want to generalise the code.

                   

                  For that 1st call that could look something like this.

                   

                  $vds = Get-VDSwitch -Name MyVDS

                  $esx = Get-VMHost -Name MyEsx


                  $spec = New-Object VMware.Vim.DVSConfigSpec

                  $spec.ConfigVersion = $vds.ExtensionData.Config.Version

                  $member = New-Object VMware.Vim.DistributedVirtualSwitchHostMemberConfigSpec

                  $member.Host = $esx.ExtensionData.MoRef

                  $member.Operation = 'add'

                  $spec.Host += $member


                  $vds.ExtensionData.ReconfigureDvs_Task($spec)

                  Blog: http://lucd.info | Twitter: @LucD22 | PowerCLI Reference co-author: http://tinyurl.com/hkn4glz
                  • 6. Re: Migrate vSphere 7 Host from vSS to vDS with PowerCLI 12
                    MC1903 Enthusiast

                    Thanks again LucD,

                     

                    From your example I have managed to get something working with the capture code.

                     

                    It is very very messy, but it works. The migration takes 2 seconds with 1 lost PING - just like in the UI.

                     

                    I can't help but feel that there is something fundamentally wrong with having to use 90+ lines of code to do what 4 vendor written PowerCLI cmdlets fail to do.

                     

                    I really appreciate your help today.

                     

                    M

                     

                    EDIT: I have tidied up the initial script, packaged as a function and dropped it on my GitHub - mc1903/Invoke-MigratevSS2vDS: A PowerShell script to migrate an ESXi Host from a vSS to a vDS