Automation

 View Only
Expand all | Collapse all

how to deploy multiple vms from template?

  • 1.  how to deploy multiple vms from template?

    Posted Dec 21, 2010 06:49 PM

    how do I deploy more than 1 vm from a template?

    I am using this command

    PS C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> New-VM -VMHost
    -esx7.domain.com -name print0001 -Template 2003ENTR2_SP2_Tmpt -Datastore "LUN 24"


  • 2.  RE: how to deploy multiple vms from template?

    Posted Dec 21, 2010 08:55 PM

    You could make a .csv file New-Vms.csv with all the information you need. Like this:

    Name,VMHost,Template,Datastore
    print0001,esx7.domain.com,2003ENTR2_SP2_Tmpt,"LUN 24"
    print0002,esx8.domain.com,2003ENTR2_SP2_Tmpt,"LUN 25"


    With this New-VMs.csv file you can create all the new virtual machines from a template with:

                

    Import-Csv -Path New-VMs.csv | `
    ForEach-Object {
      New-VM -VMHost $_.VMHost -Name $_.Name -Template $_.Template -Datastore $_.Datastore
    }
    
    

    Regards, Robert



  • 3.  RE: how to deploy multiple vms from template?

    Posted Jan 06, 2011 09:46 PM

    This should get you started.

    http://poshcode.org/2051

    Takes a fixed format CSV and pumps out clones  from a template.  Easily modified to do clones of a VM or create new  VMs.  Some of the restrictions mentioned in the notes appear to be fixed  with VMware ESX v4.1.



  • 4.  RE: how to deploy multiple vms from template?

    Posted Jan 13, 2011 06:42 PM

    can i do this from the vMA?



  • 5.  RE: how to deploy multiple vms from template?

    Posted Jan 13, 2011 06:46 PM

    Sorry, but I have no idea.



  • 6.  RE: how to deploy multiple vms from template?

    Posted Jan 16, 2011 10:04 PM

    this is my command

    param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
    $worksheet = Import-Csv $CsvFile
    $worksheet | ForEach-Object {
        new-VM -VMHost $_.VMHost `
    -Name $_.Name `
    -Template $_.Template `
            -MemoryMB $_.MemoryMB `
            -Datastore $_.Datastore `
            -NumCPU $_.NumCPU
    }
    but I am getting the error
    PS C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI> .\deployvms.ps
    1
    New-VM : Parameter set cannot be resolved using the specified named parameters.
    At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\deployvms.ps1:
    5 char:11
    +     new-VM <<<<  -VMHost $_.VMHost `
        + CategoryInfo          : InvalidArgument: (:) [New-VM], ParameterBindingE
       xception
        + FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.NewVM
    New-VM : Parameter set cannot be resolved using the specified named parameters.
    At C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\deployvms.ps1:
    5 char:11
    +     new-VM <<<<  -VMHost $_.VMHost `
        + CategoryInfo          : InvalidArgument: (:) [New-VM], ParameterBindingE
       xception
        + FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCor
       e.Cmdlets.Commands.NewVM


  • 7.  RE: how to deploy multiple vms from template?

    Posted Jan 17, 2011 06:40 AM

    Looks as if your .csv file doesn't have a VMHost column.



  • 8.  RE: how to deploy multiple vms from template?

    Posted Jan 17, 2011 04:43 PM

    I have vmhost in there. but when I use -Template It gives an error.

    param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
    $worksheet = Import-Csv -Path $CsvFile
    $worksheet | ForEach-Object {
             new-VM `
    -VMHost $_.VMHost `
    -Name $_.Name `
    -Template $_.Template `
            -MemoryMB $_.MemoryMB `
            -Datastore $_.Datastore `
            -NumCPU $_.NumCPU
    }


  • 9.  RE: how to deploy multiple vms from template?

    Posted Jan 17, 2011 07:59 PM

    Ok, I think I see what is wrong.

    You are trying to use the parameterset Template but in that parameterset you can't use -MemoryMB and -NumCPU.

    If you want to make changes to your template you have to use the -OSCustomizationSPec parameter.

    If you look at the doc for the New-VM cmdlet you'll notice that under the Syntax header there are 4 different parametersets.

    Due to the -Template parameter you fall in the Template parameterset and your other parameters have to come from the 3th entry (Template parameterset).



  • 10.  RE: how to deploy multiple vms from template?

    Posted Jan 17, 2011 08:08 PM

    I handle this by first creating the VM with –template and –oscustomizationspec with a simple spec. Then separately I do set-vm for the cpu and ram, and I also set the VLAN, custom attributes, and a few other things. For all of them I pull the data from the CSV file.

    -Chris



  • 11.  RE: how to deploy multiple vms from template?

    Posted Jan 22, 2011 09:06 PM

    Hi

    but my template is already a syspreped template so I dont see any need for a OScustomizationspec paramenter.

    But when I created one anyway and used this

    param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
    $worksheet = Import-Csv -Path $CsvFile
    $worksheet | ForEach-Object {
             new-VM `
    -VMHost $_.VMHost `
    -Name $_.Name `
    -Template $_.Template `
    -Datastore $_.Datastore `
    -OSCustomizationSpec $_.OSCustomzationSpec
    }
    it fails
    any ideas?


  • 12.  RE: how to deploy multiple vms from template?

    Posted Jan 23, 2011 01:49 AM

    Can't you create the new guest from the the template and after the creation use the Set-VM to change the CPU count and the memory ?

    param ( $CsvFile = "C:\Program Files (x86)\VMware\Infrastructure\vSphere PowerCLI\New-VMs.csv" )
    $worksheet = Import-Csv -Path $CsvFile
    $worksheet | ForEach-Object {
            new-VM `
              -VMHost $_.VMHost `
              -Name $_.Name `
              -Template $_.Template `
              -Datastore $_.Datastore | `

            Set-VM -NumCpu $numCPU -MemoryMB $memoryMB

    }