I need help trying to figure out why the new-vm cmdlet is reporting an error. Any assistance would be appreciated.
code snip (excuse the crappy line wraps)
$VIServer ="vCenterServer" Connect-VIServer $VIServer
$VMCSV_Builds = Import-Csv -Path .\VM_Config.csv
$i = 0
$VMCSV_Builds | % {
# map out my variables
$Clust = Get-Datacenter | get-Cluster ($_.Cluster)
$templatevm = $_.templatevm
$datastore = $_.datastore
$vmhost = $Clust | get-VMhost | get-random
$custspec = $_.custspec
$vmname = $_.vmname
$NUMCPU = $_.NUMCPU
$MemoryMB = $_.MemoryMB
$ipaddr = $_.ipaddress
$subnet = $_.subnet
$gateway = $_.gateway
$pdns = $_.pdns
$sdns = $_.sdns
#$vlan = $_.vlan
$description = $_.notes
#debugging
Write-Host $Clust
Write-Host $vmhost.Name
$Step = "1"
if ($Step -eq "1"){
#Step 1
# A - Connect VM
if (!(Get-VM $vmname -ErrorAction 0))
{
# B - Setup the IP address
Get-OSCustomizationSpec
$custspec | Get-OSCustomizationNicMapping |
Set-OSCustomizationNicMapping -IpMode UseStaticIp -IpAddress $ipaddr -SubnetMask $subnet -DefaultGateway $gateway -Dns $pdns,$sdns
# C - Copy the Template and apply customizations
$item = New-VM -VMhost $vmhost -Name $vmname -Template $templatevm -NumCpu $NUMCPU -MemoryMB $MemoryMB -Datastore $datastore' -DiskStorageFormat Thin -Description $description -OSCustomizationSpec $custspec -RunAsync "`n Step 1 is now being run.`n"
Get-Task | ? {
$_.id -eq $Item.id}
Start-Sleep -Seconds 30
}
else
{
"`nVM aleady exists, checking for running tasks . .`n"
$Task = @(Get-Task | ? {$_.Description -eq "Clone virtual machine"})
if ($Task)
{
#$Task
Write-Host "Task is $($Task[$i].PercentComplete) % complete."
$i++
}
else
{
"Task is complete, go onto the next step (2).`n"
}
}
}
}
end snip
this is the error that I get:
New-VM : Parameter set cannot be resolved using the specified named parameters.
At D:\Users\hal0210\desktop\Scripts\CreateVM.ps1:45 char:27
+ $item = New-VM <<<< -VMhost $vmhost -Name $vmname -Template $templatevm -NumCpu $NUMCPU -MemoryMB $MemoryMB -Datastore $datastore -Dis
kStorageFormat Thin -Description $description -OSCustomizationSpec $custspec -RunAsync "`n Step 1 is now being run.`n"
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM