xml importing values to new-vm

PowerCLI C:\Users\kon\Documents\Powerclli> $s.vmwareNEW.newvm

Template : template_win2012-r2-std-paravirtual
VMHost : aus1-esx133.mfidom.local
ResourcePool : ‘Infra-MFRM Exchange’
HDDGB : 80
Datastore : aus1-ds-esx_prod-t3-10k-04
storageformat : EagerZeroedThick
memoryGB : 4
Numofcpus : 4
portgroup : prod-corp-01

PowerCLI C:\Users\kon\Documents\Powerclli> $s.vmwareNEW.newvm | foreach { new-vm -Name $.Name -Template $.Template -VMHost $.VMHost -ResourcePool $.Res
-DiskGB $.HDDGB -Datastore $.Datastore -StorageFormat $.storageformat -MemoryGB $.memoryGB -NumCpu $.Numofcpus -Portgroup $.portgroup}

New-VM : Parameter set cannot be resolved using the specified named parameters.
At line:1 char:33

  • $s.vmwareNEW.newvm | foreach { new-vm -Name $.Name -Template $.Template -VMHo …
  •   + CategoryInfo          : InvalidArgument: (:) [New-VM], ParameterBindingException
      + FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM

Why is this ambiguous?

What it means is that the cmdlet has multiple ways of running itself, and each way has its own parameter set. You’ve probably included parameters from two sets, so the command doesn’t know which way to turn.

Simpler example that would generate the same error:

Get-EventLog -LogName Security -List

-LogName and -List belong to different parameter sets (look at the command help to see what I mean), and you can’t use them both at the same time.

It’s also possible that all the parameters you used belong to multiple parameter sets, AND you did not specify any parameters belonging to only one set, AND the command isn’t coded to have a default parameter set - so it doesn’t know which parameter set to use. That’s what it means by “ambiguous.” MOST commands do have a default parameter set (when they have multiples in the first place), but it’s something to consider. I don’t know this particular command well enough to tell you either way.

Sir You are a demi-god among men.This is a lesson l should have known and I spent a lot of hours on this trying to figure out why this was not working and it was the param set. Thank you! It says it clearly :


    Specifies the virtual machine template you want to use for the creation of the new virtual machine. Passing values to this parameter through a pipeline is deprecated and will be disabled in a future release.

    Required?                    true
    Position?                    2
    Default value                
    Accept pipeline input?       true (ByValue)
    Accept wildcard characters?  true


Stuff like this really makes me what to understand what is going on under the hood. But learning powercli has become a catalyst for me to learn powershell. I hope to build off of this and automate the entire process for my organization.

I do have another question how does one know by that generic error which switch does not belong? Other than looking it would be nice if the error displayed the param at fault.

Well, the computer doesn’t know what it is you want to do. The error message can’t be more specific because none of the parameters are “wrong.” You can’t use them in that combination, but it has no way of knowing what way would be “right” for you at the time.