We are working on a script to create multiple VM's from a template. The script works fine, but when we try to include commands to set the network adapter to a specific port group on a dvswitch the script errors out. Here is what we have so far. This script (minus the networking variables) works, but we would like to include the network configs in the script as well.
-------------------
This is the part of the script that configures the network adapter/dvswitch..., but does not work properly.
$myResourcePool = Get-ResourcePool -Name DQV
$dsName = Get-Datastore -Name "DQV-DS01"
$myTemplate = Get-Template -Name "DQVTemplate"
$distributedSwitchPortGroup = Get-VirtualSwitch -Distributed -Name "CVE-dvS04-Nexus-5k" | Get-VirtualPortGroup -Name "979-DQ-SHARED"
New-VM -Name MyVM1 -Template $myTemplate -Networkname $distributedSwitchPortGroup -ResourcePool $myResourcePool -OSCustomizationSpec $mySpecification -Datastore
(Get-Datastore $dsName)
New-VM -Name MyVM2 -Template $myTemplate -ResourcePool $myResourcePool -OSCustomizationSpec $mySpecification -Datastore (Get-Datastore $dsName)
_____________________
!!!!!!! This part works, but without specifying a networkadapter/dvswitch...!!!!!!!!!!!
$myResourcePool = Get-ResourcePool -Name DQV
$dsName = Get-Datastore -Name "CVE-SAN-ISG-DS02-02ef"
$myTemplate = Get-Template -Name "DQVTemplate"
New-VM -Name MyVM3 -Template $myTemplate -ResourcePool $myResourcePool -OSCustomizationSpec $mySpecification -Datastore (Get-Datastore $dsName)
New-VM -Name MyVM4 -Template $myTemplate -ResourcePool $myResourcePool -OSCustomizationSpec $mySpecification -Datastore (Get-Datastore $dsName)
Here is the error we get:
New-VM : Parameter set cannot be resolved using the specified named parameters.
At C:\Users\capuanoj\Desktop\Create-multiplevms-fromtemplate.ps1:6 char:7
+ New-VM <<<< -Name MyVM1 -Template $myTemplate -Networkname $distributedSwitchPortGroup -ResourcePool
ePool -OSCustomizationSpec $mySpecification -Datastore (Get-Datastore $dsName)
+ CategoryInfo : InvalidArgument: (:) [New-VM], ParameterBindingException
+ FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVM