VMware Cloud Community
PeteHow
Enthusiast
Enthusiast
Jump to solution

Script to create Multiple VMs from content library template

Hi -  I'm looking for a script that will create multiple vm's from a content library template or ova.  Where I can feed the script unique vm names, cpu, memory, choose the datastore to place the vm on as well as the cluster or host, and choose the customization spec to use, and feed it the details from a csv.  Is there a good one out there?

Thanks,

 

Pete

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

I don't know of any scripts, but basically, this is just 3 cmdlets: Get-ContentLibraryItem, Import-Csv and New-VM.

Something like this for example

$templateName = 'MyTemplate'
$template = Get-ContentLibraryItem -Name $templateName

Import-Csv -Path .\vm.csv -PipelineVariable vm |
ForEach-Object -Process {
    $sVM = @{
        ContentLibraryItem = $template
        Name = $row.VMName
        Datastore = $row.Datastore
        DiskGB = $row.DiskGB
        MemoryGB = $row.MemoryGB
        Portgroup = $row.PortgroupName
        NumCPU = $row.NumCPU
        OSCustomizationSpec= $row.OSCustomizationSpec
        # Pick one: ResourcePool allows for cluster,resourcepool, vmhost
        #ResourcePool = $row.ResourcePool
        #VMHost = $row.VMHost
    }
    New-VM @SVM
}

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

I don't know of any scripts, but basically, this is just 3 cmdlets: Get-ContentLibraryItem, Import-Csv and New-VM.

Something like this for example

$templateName = 'MyTemplate'
$template = Get-ContentLibraryItem -Name $templateName

Import-Csv -Path .\vm.csv -PipelineVariable vm |
ForEach-Object -Process {
    $sVM = @{
        ContentLibraryItem = $template
        Name = $row.VMName
        Datastore = $row.Datastore
        DiskGB = $row.DiskGB
        MemoryGB = $row.MemoryGB
        Portgroup = $row.PortgroupName
        NumCPU = $row.NumCPU
        OSCustomizationSpec= $row.OSCustomizationSpec
        # Pick one: ResourcePool allows for cluster,resourcepool, vmhost
        #ResourcePool = $row.ResourcePool
        #VMHost = $row.VMHost
    }
    New-VM @SVM
}

 


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
PeteHow
Enthusiast
Enthusiast
Jump to solution

Thanks Luc - I'll give that a try today.

0 Kudos