I use DiskGB parameter with template then this error appears:
New-VM : Parameter set cannot be resolved using the specified named parameters.
At E:\powercli\Create VM.ps1:14 char:1
+ New-VM -Name $VMName -DiskGB 40 -Template $Template -ResourcePool $vm ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM
Here is my script I use to create new vm with template:
Connect-VIServer 192.168.1.172 -Credential (Get-Credential)
#Assign Variables
$vmhost = Get-VMhost -Name 192.168.1.171
$Template = get-template -name ubuntu2004-template
$Cluster = Get-Cluster -Name FTECH
$Datastore = Get-Datastore -Name DellR620-171-datastore2
$VMname = 'test1'
$vCPU = '4'
$Memory = '8'
$Network = 'vlan90'
#Where the VM gets built
New-VM -Name $VMName -DiskGB 40 -Template $Template -ResourcePool $vmhost -StorageFormat Thin -Datastore $Datastore
#Where the vCPU, memory, and network gets set
$NewVM = Get-VM -Name $VMName
$NewVM | Set-VM -MemoryGB $Memory -NumCpu $vCPU -Confirm:$false
$NewVM | Get-NetworkAdapter | Set-NetworkAdapter -NetworkName $Network -Confirm:$false