I'm using ESXi 6.0 and PowerCLI. I've created a clone of a production VM:
$Source_VM = Get-VM -Name "MyProductionServer"
$Target_VMHost = Get-VMHost -VM $Source_VM
$Cloned_VM = (New-VM -Name "MyPreProdServer" -VM $Source_VM -VMHost $Target_VMHost)
My MyProductionServer has a static IP address set on the OS side. If I start the $Cloned_VM I will have a duplicate IP on the same subnet. What I would like to do is to DISCONNECT the NIC on the cloned VM before starting this one.
What I've found is:
1) On a powered on VM:
Get-NetworkAdapter -VM $Cloned_VM | Set-NetworkAdapter -Connected:$false -StartConnected:$false -Confirm:$false
This is working but I can't do that because of the state of the cloned VM.
2) Remove the NIC from the VM:
$spec = New-Object VMware.Vim.VirtualMachineConfigSpec
$spec.deviceChange = New-Object VMware.Vim.VirtualDeviceConfigSpec
$spec.deviceChange[0].Operation = "Remove"
$spec.DeviceChange[0].Device = $Cloned_VM.ExtensionData.Config.Hardware.Device | ?{$_.DeviceInfo.Label -eq "Network adapter 1"}
$Cloned_VM.ExtensionData.ReconfigVM_Task($spec)
Source: https://communities.vmware.com/thread/454525
This is working too but it's not exactly what I would like.
I would like to DISCONNECT the current NIC to let me boot the cloned VM, changing the IP address then CONNECT the NIC (+ reboot) to have the cloned VM working with another IP address.
In simple words, I would like to do the 1) on a powered off VM. Is that possible ?