Iam trying to deploy VMs with this script, input file has vmname, temp name, datastore name, customspec name and network name also cpu,mem.
I have added resourcepool directly to script. I was trying to add different network names to the csv file so as to deploy vms evenly on all VLANs.
getting below error, can someone please help, thanks
$VirtualMachinesCSV = "new.csv"
$strDescription = "test"
$clusterName = "cluster1"
$VirtualMachinesDetails = Import-CSV $VirtualMachinesCSV
$VirtualMachinesDetails | %{ New-VM -Name $_.Name -Template $(Get-Template $_.Template) -ResourcePool $clusterName -Datastore $(Get-Datastore $_.Datastore) -Networkname $(Set-NetworkAdapter $_.Network) -OSCustomizationSpec $(Get-OSCustomizationSpec $_.CustomSpec) }
$VirtualMachinesDetails | %{ Set-VM -VM $_.Name -NumCpu $_.NumCpu -MemoryMB $_.MemoryMB -Description $strDescription -Confirm:$false }
$VirtualMachinesDetails | %{ Start-VM -VM $_.Name -Confirm:$false }
error
Set-NetworkAdapter : Cannot bind parameter 'NetworkAdapter'. Cannot convert
the "FRA02-W7-CLIENT-860" value of type "System.String" to type
"VMware.VimAutomation.ViCore.Types.V1.VirtualDevice.NetworkAdapter".
You are using New-VM parameters that are not in the same parameterset.
You could do something like this
$VirtualMachinesCSV = "new.csv"
$strDescription = "test"
$clusterName = "cluster1"
$VirtualMachinesDetails = Import-CSV $VirtualMachinesCSV
$VirtualMachinesDetails | %{
$vm = New-VM -Name $_.Name -Template $_.Template -ResourcePool $clusterName -Datastore $_.Datastore -OSCustomizationSpec $_.CustomSpec
Set-VM -VM $vm -NumCpu $_.NumCpu -MemoryMB $_.MemoryMB -Description $strDescription -Confirm:$false
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $_.Network
Start-VM -VM $vm -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
That should be a string, like this
-Networkname $_.Network
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Sorry, but like this
-Networkname $(Set-NetworkAdapter $_.Network)
No, without the Set-NetworkAdapter, the NetworkName parameter expects a string, just the name.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
trying with this in the script
-Networkname ($_.Network)
getting error : New-VM : Parameter set cannot be resolved using the specified named parameters.
You are using New-VM parameters that are not in the same parameterset.
You could do something like this
$VirtualMachinesCSV = "new.csv"
$strDescription = "test"
$clusterName = "cluster1"
$VirtualMachinesDetails = Import-CSV $VirtualMachinesCSV
$VirtualMachinesDetails | %{
$vm = New-VM -Name $_.Name -Template $_.Template -ResourcePool $clusterName -Datastore $_.Datastore -OSCustomizationSpec $_.CustomSpec
Set-VM -VM $vm -NumCpu $_.NumCpu -MemoryMB $_.MemoryMB -Description $strDescription -Confirm:$false
Get-NetworkAdapter -VM $vm | Set-NetworkAdapter -NetworkName $_.Network
Start-VM -VM $vm -Confirm:$false
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks,
it works like charm and it only asks for confirmation before powering on. I believe a confirm-false would fix it.
Strange, there is a -Confirm:$false on the Start-VM cmdlet.
And it still prompts?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
yes,
even strange is the set-network adapter function which won't work without get-network adapter