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

This post was originally published on this site

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:Usersvk185112Desktopvinvappvcloudvms.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
$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
Remove-VM -VM $ -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 





csv file

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.