12 Replies Latest reply on Feb 15, 2019 2:44 AM by vin01

    change mac address from manual to automatic and remove cloud.uuid in vm advanced setting

    vin01 Hot Shot

      I have a set of vms in a csv file which I am trying to modify vm advanced settings and unregister and register back as new name in different resource pool but i am failing to remove cloud.uuid and make the network adapter mac as automatic while reconfigvm ($registernewvravm.ExtensionData.ReconfigVM($vmConfigSpec))

      $csvimportvms=Import-Csv -Path C:\Users\vk185112\Desktop\vinvappvcloudvms.csv
      foreach($vcloudvmscsv in  $csvimportvms){
      $registernewvravm= Get-VM $vcloudvmscsv.OldVMName
      $nicName= Get-NetworkAdapter -VM $registernewvravm
      $vmConfigSpec = New-Object VMware.Vim.VirtualMachineConfigSpec
      $dev = New-Object VMware.Vim.VirtualDeviceConfigSpec 
      $vmConfigSpec.extraconfig += New-Object VMware.Vim.optionvalue
      $vmConfigSpec.extraconfig[0].Key="cloud.uuid" 
      $vmConfigSpec.extraconfig[0].Value=$null
      $dev.operation = "edit" 
      $registernewvravm.ExtensionData.Config.Hardware.Device | where {$_.DeviceInfo.Label -eq $nicName.Name} | %{
       $dev.device = $_    
          if($dev.device.addressType -eq "manual"){
             $dev.device.addressType= 'assigned'
              $dev.Device.MacAddress = $null  
              }
              }
      $vmConfigSpec.DeviceChange += $dev
      $registernewvravm.ExtensionData.ReconfigVM($vmConfigSpec)
      Remove-VM -VM $registernewvravm.name -DeleteFromDisk:$false -Confirm:$false -RunAsync
      $newVM = New-VM -VMFilePath $registernewvravm.ExtensionData.Config.Files.VmPathName -ResourcePool $vcloudvmscsv.NewResourcePool -Name $vcloudvmscsv.NewVMName
      Start-VM -vm $newVM 
      Get-VMQuestion -vm $newVM | Set-VMQuestion -Option "button.uuid.movedTheVM" -Confirm:$false 
      
      }
      

       

      error:

       

      csv file

      Regards
      Vineeth.K