In the last post I anounced the new PowerCLI Extensions fling, which allows admins to leverage the Instant Clone abilities found in vSphere 6. Today I’m going to walk you through how to use it.
Prerequisites
To be able to fully leverage PowerCLI Extensions, you will need to meet the following requirements:
- VMware PowerCLI 6.0 R1 or higher
- PowerShell v2 or higher
- vSphere 6
Installation
- Download the latest release of PowerCLI
- Download PowerCLI Extensions on the VMware Fling page HERE
- Right-Click the PowerCLI Extensions zip file, click Properties, and select ‘Unblock’.
- Unzip the contents of the PowerCLI Extensions fling and place them in your PowerShell modules directory (do not rename the folder)
- Ensure the VMware.VimAutomation.Extensions folder is only a single directory deep. (module files should be in the next level down)
Using Instant Clone
before creating a parent VM, you will want to ensure that you get your intended-parent VM is in the intended state for the child VMs to pick up and continue. You will also want to create a ‘Post Clone Script’ to attach to the parent VM which will run as each child VM is started. For Windows, this would be a batch (.bat) script, for linux this would be a shell (.sh) script. an example of a Windows Post Clone Script created by Deji Akomolafe, Staff Solutions Architect at VMware is below:
##### In-Guest Customization script
“%programfiles%\vmware\vmware tools\rpctool” “info-get guestinfo.fork.ipaddress” > c:\ip.txt
“%programfiles%\vmware\vmware tools\rpctool” “info-get guestinfo.fork.gateway” > c:\gateway.txt
set /p ip=<c:\ip.txt
set /p gateway=<c:\gateway.txt
FOR /F “tokens=2,3* ” %%j in (‘netsh interface show interface ^| find “Connected”‘) do set ConnnectedNet=%%l
netsh interface ipv4 set address name=%ConnnectedNet% static %ip% 255.255.255.0 %gateway%
netsh interface set interface %ConnnectedNet% DISABLED
netsh interface set interface %ConnnectedNet% ENABLED
Once you’ve created your Post Clone Script, you can move on to creating your Parent VM
- Open PowerCLI and import the module
- import-module VMware.VimAutomation.Extensions
- Connect to your vCenter Server
- Connect-VIServer <your vCenter address>
- Specify your intended parent VM
- $parentVM = Get-VM Parent2012
- Enable the $parentVM as an instant-clone parent
- $parentForkVM = Enable-InstantCloneVM -VM $parentVM -guestUser “administrator” -GuestPassword “VMw@re123” -PostCloneScript C:\temp\WindowsPostScript.bat
- Add any configuration parameters you want to be able to pass to the child VM
- $ConfigSettings = @{
‘ipaddress’ = “10.134.14.75”;
‘netmask’ = ‘255.255.255.0’;
‘gateway’ = ‘10.134.14.253’;
‘dns’ = ‘10.134.14.9’;
}
- $ConfigSettings = @{
- Create the Instant-clone child VM and attach the configuration parameters
- $childForkVm = New-InstantCloneVM -ParentVM $parentForkVM -Name Child2012 -ConfigParams $ConfigSettings
- Start the child VM
- $childForkVm | Start-VM
DEMO
Creating multiple child VMs
Using the same commands as we did above, we can create as many instant-clone VMs as we want. To keep things simple as far as IP addresses go, this example will deploy 9 child VMs from the 2012 parent.
1..9 | Foreach {
$configSettings = @{
‘ipaddress’ = “10.134.14.13$_”;
‘netmask’ = ‘255.255.255.0’;
‘gateway’ = ‘10.134.14.253’;
}Write-Host “Creating Clone$($_)…”
$childForkVm = New-InstantCloneVM -ParentVM $parentforkVm -Name “2012ChildClone$_” -ConfigParams $configSettings
$childForkVm | Start-Vm -RunAsync | Out-Null
}
as you can see from above, the only items that have really changed from creating a single child VM is that we piped a series of numbers (1-9) in the command and for each number, it creates a virtual machine with an ip address 10.134.14.13_ where _ is the number that was piped in. The names of the VMs are also identified using the piped value, creating
Additional Actions
Sections 7 and 8 of the PowerCLI extensions guide give many examples of what can be done with Instant Clone. For additional examples please refer to these sections.
Things to know
Parent VMs
Once a VM becomes a parent VM, it has limited operations it can do. Parent VMs cannot be used or edited while running as a parent. To release it from being a parent VM, you must power that VM off. You will notice that the other power options are not available while running as a parent. See section 5.1 of the PowerCLI Extensions guide for more details on parent operations.
Child VMs
A child VM can be powered-on, off, and reset. It can be deleted once the VM is powered-off. It can be unregistered, and it can be reconfigured to add disks only. additional operations may be supported in the future, but are not at this current time.
Does this work if the parent and child are using DHCP assigned IP addresses? Also what happens to the child hostname(s)? We currently use linked clones in vsphere 5.5 and the process of spinning up clones is fast but the guest customization to make sure the children have unique names, reboot etc takes longer than we would like.
Hi Jeremy,
1) For DHCP, You can use a different post clone script, something like:
netsh interface ipv4 set address dhcp
netsh interface set interface DISABLED
netsh interface set interface ENABLED
2) For hostname configurations, you can simply add ‘hostname’ param to the $configSettings part, and then use it from within the post clone script just like the other params.
Ammm…for some reason my last comment seem to be only partially submitted. (probably it’s removing env vars automatically)
Anyway.. Of course in each line you’ll need the interface name (for example: “Local Area Connection”)
Hi,
Can you help me? I see this and I’m not sure how to get around it. THANKS!!!!
PowerCLI C:\> $vm = get-vm Win10_1
PowerCLI C:\> $parentvm = Enable-InstantCloneVM -VM $vm -guestUser “Administrator” -GuestPassword “XXXXX” -PostCloneScript “C:\PostCloneScript.bat”
Enable-InstantCloneVM : 4/28/2016 5:10:16 PM Enable-InstantCloneVM Method not found: ‘System.Web.Services.Protocols.SoapHttpClientProtocol VMware.Vim.VimClient.get_VimService()’
At line:1 char:13
+ $parentvm = Enable-InstantCloneVM -VM $vm -guestUser Administrator -GuestPasswor …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-InstantCloneVM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Extensions.InstantClone.Commands.EnableInstantCloneVM
PowerCLI C:\>
You are getting this error because, I think, you are not running the PowerCLi 631R1 specific extension. When you go to download the extension zip file, make sure to select the one for 631R1 and above from the dropdown menu. That did it for me.
Hi, Can someone please help me, Getting error as below most of the time and not able to proceed further. (Followed the same steps mentioned here in this blog, and was able to succeed earlier, but now getting this error)
Thanks
————
New-InstantCloneVM : Cannot bind argument to parameter ‘VM’ because it is null.
At line:1 char:45
+ $childForkVM = New-InstantCloneVM -ParentVM $parentForkVM -Name vMtest
-Confi …
+ ~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [New-InstantCloneVM], Parameter BindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,VMware.VimAutomation.Extensions.InstantClone.Commands.NewInstantCloneVM
Hello bmadhav
Do you have any update about this issue that I have the same
Thanks for you help
Regards
is this working on vsphere 6.5? Why the instantclone cmdlets are not included in PowerCLI 6.5? I am running 6.5 and downloaded the extension (VMware.VimAutomation.Extensions_for_PCLI_65R1) but fails with this error:
PowerCLI C:\> Enable-InstantCloneVM -vm $a -GuestUser administrator -GuestPassword password -PostCloneScript C:\pscript.bat
Enable-InstantCloneVM : 1/9/2017 2:36:45 AM Enable-InstantCloneVM A general system error occurred: vix error codes =
(1, 0).
At line:1 char:1
+ Enable-InstantCloneVM -vm $a -GuestUser administrator -GuestPassword …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-InstantCloneVM], SystemError
+ FullyQualifiedErrorId : Client20_VmGuestServiceImpl_RunScriptInGuest_ViError,VMware.VimAutomation.Extensions.Ins
tantClone.Commands.EnableInstantCloneVM
Enable-InstantCloneVM : 1/9/2017 2:36:45 AM Enable-InstantCloneVM Object reference not set to an instance of an
object.
At line:1 char:1
+ Enable-InstantCloneVM -vm $a -GuestUser administrator -GuestPassword …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Enable-InstantCloneVM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.Extensions.InstantClone.Commands.Enabl
eInstantCloneVM
Hi albert I have encountered the same problem with you. Do you slove it now? I have no idea with it…
Hi, I think, you are not running the PowerCLi 631R1 specific extension. Anyway… Of course in each line, you’ll need the interface name. thanks
Now the world is all on the mobile phone. There is no outing and none other entertainment. So in this Difficult era of World Pinoy TV is providing the Special Show of Pinoy Lambingan and Pinoy Tambayan.
Kasauti Zindagi Ki is the best Star Plus Drama of All The Time.