Automation

 View Only
  • 1.  Can we move-vm to more than one NIC properly

    Posted Jun 20, 2022 01:07 PM

    Hi ,

    I have a requirement to move VMs from one esxi to other esxi with Move-VM but unable to figure out if we have more NICs on VM like  3 , 4 , 5 ,6 NICs , is it possible to move to right adapter to right port group. below is the script in my mind kindly help.

    $networkAdapter = Get-NetworkAdapter -vm VMname
    if ($networkAdapter.Count -ge 1) {

    foreach ( $nadapter in $networkAdapter) {

    $destinationPortGroup = Get-VDPortgroup -VDSwitch 'NewvDS' -Name "$($nadapter.NetworkName)-new"
    Move-VM -VM VMname -Destination Esxiserver -NetworkAdapter $nadapter -PortGroup $destinationPortGroup -WhatIf

    }

    }

     

     

     



  • 2.  RE: Can we move-vm to more than one NIC properly

    Posted Jun 20, 2022 01:42 PM

    The Move-VM cmdlet parameters NetworkAdapter and Portgroup both accept an array of values.
    That allows you to specify per vNIC to which destination portgroup they shall be moved.



  • 3.  RE: Can we move-vm to more than one NIC properly

    Posted Jun 20, 2022 02:06 PM

    Could you please help with sample code to test from my end. Thank you in advance.



  • 4.  RE: Can we move-vm to more than one NIC properly
    Best Answer

    Posted Jun 20, 2022 02:13 PM

    You could try something like this

    $vNic = Get-NetworkAdapter -VM VMname
    $pg = $vNic | %{Get-VirtualPortGroup -Name "$($_.NetworkName)-new"}
    
    Move-VM -VM VMName -Destination Esxiserver -NetworkAdapter $vNic -PortGroup $pg