Feb 25 2014

Create multiple VMs from existing vSphere VM using PowerCLI

I recently published the blog post “Create multiple VMs using PowerCLI” and as i mentioned in the post i thought the next request would be a PowerCLI script to create multiple VMs from an existing vSphere virtual machine (VM). It just took a few days before the request reached my email inbox. I actually received a few email from my readers requesting the same thing and also a comment on the previous blog post.

The previous PowerCLI script used the following sequence:

  1. Issued the command for creating a VM.
  2. Waited until the VM was created.
  3. Powered the VM on.

When all three above steps were finished the next VM was created. The new request included an additional sequence where the script should continue as soon as the vCenter Server has accepted the “create new VM command”.
This means we will put much more pressure on the storage array and my customer wanted to verify the VAAI functionality.
And yes, the VM we used as the base VM had its disk in format “Thick Eager Zeroed”

There were a couple of requirements for the script as well.

  • Specify the number of VMs to be created.
  • Specify a customization specification to be used.
  • The VMs must be placed on all ESXi hosts in the vSphere cluster.
  • Specify a vCenter Server Folder in the Virtual Machine & Templates view where the VMs will be placed.
  • Specify VM datastore/datastore cluster placement.
  • Specify the VM prefix.
  • Use numeric incremental number after the VM prefix.

If you want to use the same sequence described in the “Create multiple VMs using PowerCLI” you can:

  • Remove the -RunASync from the below script.
  • Add the following lines, after the “New-VM” line but before the } sign:
    • write-host “Power On of the  VM $VM_name initiated”  -foreground green
    • Start-VM -VM $VM_name -confirm:$false -RunAsync

The script were tested using the following software versions:

  • VMware vCenter Server 5.5
  • VMware ESXi 5.5
  • VMware PowerCLI 5.5 (32-bit mode)
  • Microsoft PowerShell 2.0

Change the following parameters for the below script:

  • $vCenter=”vc-demo01.vcdx56.com”
  • $vCenterUser=”vcdx56@a_magnus”
  • $vCenterUserPassword=”notsecret”
  • $vm_count = “100”
  • $clone = “VCDX56-base-vm”
  • $customspecification=”VCDX56-customization”
  • $ds = “DSC-VDX56-01”
  • $Folder = “Scripttest”
  • $Cluster = “CLU-VCDX56-01”
  • $VM_prefix = “VCDX56-“


Important: The customspecification works in 32-bit mode only so make sure you run the script using the PowerCLI 32-mode version.


3 pings

Skip to comment form

  1. Michael

    And if you want to create the vms from a template? With what should be $clone replaced?

  2. magander3

    haven’t used it for a few years since it will be disabled, check this out https://www.vmware.com/support/developer/PowerCLI/PowerCLI51/html/New-VM.html , but try change VM to Template


  3. Diego


    Great script, help me a lot

    Brazilian thanks

  4. magander3

    Glad you found it useful.


  5. Frank

    Works great! What would be the best way to select multiple datastores?

  6. magander3

    Maybe use datastore clusters and let vSphere manage that?


  7. Sunil

    Works Great.

    Thanks Much !!

    Any idea how to clone multiple vms of different names??


  8. magander3

    Hi Sunil,
    do you mean cloning different VMs or crete VMs from another VM and give the VMs different names (not only different numbers at the end)?


  9. tnguyen

    I want to do this but creating LinkedClone from a snapshot ..like here
    new-VM -Name AUTONEW -VM $mySourceVM -LinkedClone -ReferenceSnapshot $myReferenceSnapshot -Resourcepool $cluster -Datastore $myDatastore

  10. Situs Poker Online Uang Asli Indonesia

    Create multiple VMs from existing vSphere VM using PowerCLI » VCDX56
    Situs Poker Online Uang Asli Indonesia http://feraripoker.com/

  11. Situs Poker Online Uang Asli Indonesia

    Hi there, I check your Create multiple VMs from existing vSphere VM using PowerCLI » VCDX56 blogs regularly. Your writing style is awesome, keep up the good work! Situs Poker Online Uang Asli Indonesia http://feraripoker.com/

  12. Ronald


    Do you have a script to create VM snapshot of different VMs in different locations?
    By the way, the above script was very helpful.

    Thank you.


  13. Nawal Singh

    This script is working fine but I need to create VMs name with start TEST33 . Can you please let me know where and what value need to change so that the VM creation will start with TEST33.

  1. Create multiple VMs using PowerCLI | VCDX56

    […] 2014-02-25 – As i suspected, here you can find a post in which i create multiple VMs, based on one existing vSphere VM, using […]

  2. SQL Server Templates with VMware – Dude Where’s My Drive Letters? | Long White Virtual Clouds

    […] After the VM reboots you can log in and review the lot files diskpartlog.txt and powercfglog.txt to ensure the output is as you expect. You can also review the drive letters and that your SQL Database starts as expected. The first time you run through this you should verify that everything is as you expect it, then you can have confidence when you clone many more VM’s everything will work. If you want to clone lots of VM’s you might like to check out an article by Magnus Andersson (VCDX56) – Create multiple VMs from existing vSphere VM using PowerCLI. […]

  3. Newsletter: January 17, 2014 | Notes from MWhite

    […] you want to spin up a bunch of VM’s there is a nice script here that can help.  Nice […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">