Hi,
I am looking for PowerCli script to deploy VMs from template, the aim from that script is deploy a VM different VM hardware configuration from the template such number of vCPU, RAM, ....etc.
Thank you
The vCPU and RAM are already done with the Set-VM cmdlet.
For the disk you will have to use the Set-HardDisk cmdlet.
$templateName = 'template'
$esxName = 'esx'
$dsName = 'ds'
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $dsName
$esx = Get-VMHost -Name $esxName
$vm = New-VM -Template $template -Name stressTest -VMHost $esx -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Basically you can pipe the New-VM and Set-VM cmdlets together to achieve something like that.
$templateName = 'template'
$esxName = 'esx'
$dsName = 'ds'
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $dsName
$esx = Get-VMHost -Name $esxName
New-VM -Template $template -Name MyVM -VMHost $esx -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false |
Start-VM -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
I would like to set number of vCPU, RAM and disk size, Can I do that ?
The vCPU and RAM are already done with the Set-VM cmdlet.
For the disk you will have to use the Set-HardDisk cmdlet.
$templateName = 'template'
$esxName = 'esx'
$dsName = 'ds'
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $dsName
$esx = Get-VMHost -Name $esxName
$vm = New-VM -Template $template -Name stressTest -VMHost $esx -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD
I tried to point to a cluster instaed of host , but did not work with me. Can I use change the host to a cluster in the script ?
templateName = 'Temp-01'
$Cluster = "test01"
$ds = "Datastore_02"
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $ds
$ESXi= Get-Cluster $Cluster
$vm = New-VM -Template $template -Name stressTest $ESXi=Get-Cluster $Cluster -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
Try with the ResourcePool parameter instead of the VMHost parameter.
$templateName = 'template'
$esxName = 'esx'
$clusterName = 'cluster'
$dsName = 'ds'
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $dsName
$cluster = Get-Cluster -Name $clusterName
$esx = Get-VMHost -Name $esxName
$vm = New-VM -Template $template -Name NewVM -ResourcePool $cluster -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I need help, I've copied the above the script and change the required things but the script is not working, could you please some help. please see the below script, I don't have vm host name but i have IP address.
$templateName = 'template'
$esxName = 'esx'
$clusterName = 'cluster'
$dsName = 'ds'
$template = Get-Template -Name $IDS-DEP-VM14-Server-2008-BaseImage
$ds = Get-Datastore -Name $DHI DS #002 - FC
$cluster = Get-Cluster -Name $DHI CLU #02 - VDI
$esx = Get-VMHost -Name $10.5.10.231
$vm = New-VM -Template $template -Name Rizwannewvm -ResourcePool $cluster -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
The $ in front of the IP address on the Get-VMHost line is causing the error.
Same goes for the Get-Datastore line.
Set the names in the variables.
$templateName = 'IDS-DEP-VM14-Server-2008-BaseImage'
$esxName = '10.5.10.231'
$clusterName = 'DHI CLU #02 - VDI'
$dsName = 'DHI DS #002 - FC'
$template = Get-Template -Name $templateName
$ds = Get-Datastore -Name $dsName
$cluster = Get-Cluster -Name $clusterName
$esx = Get-VMHost -Name $esxName
$vm = New-VM -Template $template -Name Rizwannewvm -ResourcePool $cluster -Datastore $ds -DiskStorageFormat Thin |
Set-VM -NumCpu 2 -MemoryGB 4 -Confirm:$false
Get-HardDisk -VM $vm | Set-HardDisk -CapacityGB 100
Start-VM -VM $vm -Confirm:$false
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Since your new questions are a bit outside the scope of this thread, I suggest you create one or more threads with your new questions.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hello Dear,
As you given me directions so I've created another discussion, could you please help me with it.
How do i add OS customization like OS Name and IP configuration inside the VM
Thank you
Rizwan
How do i add OS customization like OS Name and IP configuration inside the VM
Hopefully this thread isn't dead, Great script but I would like some insight to take it a couple steps further. In need of ability to do:
* Change Host name
* Add to the Domain
* upgrade Vmtools and vm hardware
* Ip server, gateway, subnetmask and two dns servers
* Were on Vsphere 6.7 so ability to enable CPU hot plug, and Memory hot plug. Also enable - Check and upgrade vmware tools before each power on.