4 Replies Latest reply on Feb 7, 2019 12:56 PM by LucD

    Clone VM with MAC addres of VM origen

    marco2601 Novice

      I have the following code to clone a machine, can you help me to be able to clone with the same MAC as the source VM?

       

      Regards

       

      ##Clone VM, disco virtual tipo thick y carpeta de almacenaiento de la VM

      New-VM -VM $VMsource -Name $newVMclone -VMHost $esxi -DiskStorageFormat Thin -Location "Laboratorios"

        • 1. Re: Clone VM with MAC addres of VM origen
          LucD Guru
          Community WarriorsvExpertUser Moderators

          Afaik, you can't do this with the New-VM cmdlet.

          But you can change the MacAddress after the clone is created.

           

          $vmOrginalName = 'MyVM'

          $vmCloneName = 'MyClone'


          Get-VM -Name $vmCloneName |

             Get-NetworkAdapter |

             Set-NetworkAdapter -MacAddress (Get-VM -Name $vmOrginalName | Get-NetworkAdapter).MacAddress

          • 2. Re: Clone VM with MAC addres of VM origen
            marco2601 Novice

            Apply the following code, the cloning does it without problems, but at the moment of configuring the MAC to VM cloned it shows me the following error:

             

            Error

            -------------------------------------------

             

            Set-NetworkAdapter : 2/7/2019 3:14:46 PM        Set-NetworkAdapter              The MAC address is invalid or is not in the valid range

            00:50:56:00:00:00 - 00:50:56:3F:FF:FF.

            At C:\Users\Marco\Desktop\clonacion.ps1:23 char:49

            + ... rkAdapter | Set-NetworkAdapter -MacAddress (Get-VM -Name $VMsource |  ...

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

                + CategoryInfo          : InvalidArgument: (:) [Set-NetworkAdapter], InvalidArgument

                + FullyQualifiedErrorId : Common_SharedParameterHelper_TryValidateStaticMacAddress_InvalidMacAddress,VMware.VimAut

               omation.ViCore.Cmdlets.Commands.VirtualDevice.SetNetworkAdapter

             

             

            SCRIPT

            ----------------------------------

             

            ##Connect to vCenter

            connect-viserver -server $vcenter_server -User $vcenter_user -Password $vcenter_pwd

             

             

            ##Elimina VM de hasta 7 dias

            Get-VM -Name $oldCloneName -ErrorAction SilentlyContinue | Remove-VM -DeletePermanently:$true -Confirm:$false

             

             

            ##Clone VM, disco virtual tipo thick y carpeta de almacenaiento de la VM

            New-VM -VM $VMsource -Name $newVMclone -VMHost $esxi -DiskStorageFormat Thin -Location "Laboratorios"

             

             

            ##Asignar MAc de la VM origen

            Get-VM -Name $newVMclone | Get-NetworkAdapter | Set-NetworkAdapter -MacAddress (Get-VM -Name $VMsource | Get-NetworkAdapter).MacAddress

            • 3. Re: Clone VM with MAC addres of VM origen
              a.p. Guru
              Community WarriorsvExpertUser Moderators

              The MAC address is invalid or is not in the valid range 00:50:56:00:00:00 - 00:50:56:3F:FF:FF

              Manually configured MAC addresses have to be in the mentioned range.

              Does the source have a manually configured MAC address in that range?

              Also note that duplicate MAC addresses may not work, and even if you can set it, it may be changed afterwards by the ESXi host, or vCenter to avoid MAC address conflicts.

               

              André

              • 4. Re: Clone VM with MAC addres of VM origen
                LucD Guru
                User ModeratorsCommunity WarriorsvExpert

                When the Mac address of the source VM is not in the allowed range, use the API method Matt showed in Re: Keeping the MAC Address when cloning a VM