2 Replies Latest reply on Nov 5, 2017 7:58 AM by vijayrana968

    Linux Template : Multiple VMs deployment.

    vijayrana968 Master
    vExpert

      I am using script created by RvdNieuwendijk

       

      https://www.vmadmin.co.uk/resources/48-vspherepowercli/272-vspherevmtemplatecsv 

       

      Input CSV columns are :

      Name

      Template

      DestinationHost

      CustomSpec

      NumCpu

      MemoryMB

       

      Actual script is :

       

      Connect-VIServer vcenter1.vmadmin.co.uk

      $VirtualMachinesCSV = "C:\VMsFromTemplate.csv"
      $strDescription = "Created from template and CSV by Andy Barnes"

      $VirtualMachinesDetails = Import-CSV $VirtualMachinesCSV
      $VirtualMachinesDetails | %{ New-VM -Name $_.Name -Template $(Get-Template  $_.Template) -VMHost $(Get-VMHost $_.DestinationHost) -OSCustomizationSpec $(Get-OSCustomizationSpec $_.CustomSpec) }
      $VirtualMachinesDetails | %{ Set-VM -VM $_.Name -NumCpu $_.NumCpu -MemoryMB $_.MemoryMB -Description $strDescription -Confirm:$false }
      $VirtualMachinesDetails | %{ Start-VM -VM $_.Name -Confirm:$false }

       

       

      This is working fine for me with given information, however I am looking to add some more parameters which I am not able to find with SET-VM command like to specify Datastore, Multiple NICs, Multiple disks, Port groups to attach, and folder.

      Thanks in advance.

        • 1. Re: Linux Template : Multiple VMs deployment.
          mattboren Master
          vExpert

          Hello, -

           

          Here are some tips that should get you going in the right direction to update your code to support specifying those additional items:

           

          Datastore:

          • add a property (a "column") in the CSV for Datastore, in which you specify the datastore or datastorecluster for the given VM
          • add the parameter -Datastore to the New-VM call, with a value of ($_.Datastore)

           

          folder

          • Similar to the Datastore tidbit above, add a property (a "column") in the CSV for Folder, in which you specify the unique name of the vSphere inventory folder in which to place the given VM
          • add the parameter -Location to the New-VM call, with a value of (Get-Folder -Name $_.Folder)

           

          Multiple NICs, and specify PortGroups

          • it's probably clear by now, but, add some property for the number of additional VM NICs to add to the VM; this might just be an array of vPG names, to be used for each new VM NIC
          • add a bit of code that adds that number of NICs to the new VM and with the desired vPG (using New-NetworkAdapter)

           

          Multiple disks

          • add a property to the CSV that is an array of sizes of new virtual disks to add to each VM (if any)
          • add a bit of code that adds the given number of virtual disks, and of the given sizes (using New-HardDisk and its parameter -CapacityGB)

           

          That get you there?

          1 person found this helpful
          • 2. Re: Linux Template : Multiple VMs deployment.
            vijayrana968 Master
            vExpert

            Thanks for inpu, let me try this.