VMware Cloud Community
Rhidian
Contributor
Contributor
Jump to solution

Clone a VM and Chnage it's Network Settings?

I'm looking to clone a VM multiple times changing the network connection and IP address it uses,  any help appreciated.

Reply
0 Kudos
1 Solution

Accepted Solutions
varonis
Enthusiast
Enthusiast
Jump to solution

NP, other solution will be running this script :

$vmlist = Import-CSV C:vms.csv
foreach ($item in $vmlist) {
  # I like to map out my variables
  $vmname = $item.vmname
  $ipaddr = $item.ipaddress
  $subnet = $item.subnet
  $gateway = $item.gateway
  $pdnswins = $item.pdnswins
  $sdnswins = $item.sdnswins
  #Get the current interface info
  $GuestInterface = Get-VMGuestNetworkInterface -VM $vmname -HostCredential $HostCred -GuestCredential $GuestCred
  #If the IP in the VM matches, then I don't need to update
  If ($ipaddr -ne $($GuestInterface.ip)) {
      Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $GuestInterface -HostCredential $HostCred -GuestCredential $GuestCred -IP $ipaddr -Netmask $subnet -Gateway $gateway -DNS $pdnswins,$sdnswins -WINS $pdnswins,$sdnswins
  }
}

View solution in original post

Reply
0 Kudos
10 Replies
rajeshcloud
Enthusiast
Enthusiast
Jump to solution

You can clone multiple times, but you should change ip address for each machine.

Regards,Rajesh, if you found this or other information useful, please consider awarding points for "Correct" or "Helpful"
Reply
0 Kudos
Rhidian
Contributor
Contributor
Jump to solution

I'm looking to do somthing like this;

Connect-vCenter

     Connect-Cluster

     Get-AllAvailableNetworks

     For AllTheAvailableNetworks

          Clone-VM(Update Network Addapter(AllTheAvailableNetworks), ChangeIP)

     END

Reply
0 Kudos
Shakaal
Hot Shot
Hot Shot
Jump to solution

Hi,

Make a template out of the VM and use guest customization, also check if during cloning it gives option for guest customization if it does then no need to go for template just use guest customization follow below Kb artilce for guest customization:

http://kb.vmware.com/kb/1006842

Regards

varonis
Enthusiast
Enthusiast
Jump to solution

Hi,

You can clone and than remove the the network card, recreate network card (if you have a DHCP server) you will get a new ip.

Add-PSSnapin VMware.VimAutomation* -erroraction SilentlyContinue
Connect-VIServer -Server vc

$VM = Get-Vm "networktest"

foreach ($VM in $VMs)
    {
     $VM | Get-NetworkAdapter | remove-NetworkAdapter -Confirm:$false
    New-NetworkAdapter -VM $VM -NetworkName "VM Network" -StartConnected -Confirm:$false
    }

tigerdeccan
Enthusiast
Enthusiast
Jump to solution

If you are cloning and recreating it should already have new IP and DNS name ,

Reply
0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

not true... if you clone it cloning everything!

if you deploy from a template it will get a new ip and dns...

Reply
0 Kudos
tigerdeccan
Enthusiast
Enthusiast
Jump to solution

sorry I have had wrong conception...

yeah u r right ..

I thought you guys r cloning to template ...

Reply
0 Kudos
tigerdeccan
Enthusiast
Enthusiast
Jump to solution

If you rather prefer to clone it to template and deploy VMs , then Vspherw will do the job .

You will need to include a sysprep script in c:\windows\setup .. 

Reply
0 Kudos
varonis
Enthusiast
Enthusiast
Jump to solution

NP, other solution will be running this script :

$vmlist = Import-CSV C:vms.csv
foreach ($item in $vmlist) {
  # I like to map out my variables
  $vmname = $item.vmname
  $ipaddr = $item.ipaddress
  $subnet = $item.subnet
  $gateway = $item.gateway
  $pdnswins = $item.pdnswins
  $sdnswins = $item.sdnswins
  #Get the current interface info
  $GuestInterface = Get-VMGuestNetworkInterface -VM $vmname -HostCredential $HostCred -GuestCredential $GuestCred
  #If the IP in the VM matches, then I don't need to update
  If ($ipaddr -ne $($GuestInterface.ip)) {
      Set-VMGuestNetworkInterface  -VMGuestNetworkInterface $GuestInterface -HostCredential $HostCred -GuestCredential $GuestCred -IP $ipaddr -Netmask $subnet -Gateway $gateway -DNS $pdnswins,$sdnswins -WINS $pdnswins,$sdnswins
  }
}
Reply
0 Kudos
tigerdeccan
Enthusiast
Enthusiast
Jump to solution

will this change the DNS name and IP address . if yes , then you might also consider any traffic hitting the parent VM and also address the issues involving in duplicate machines for few seconds/minutes untill this script execute 

Reply
0 Kudos