VMware Cloud Community
deensolea
Contributor
Contributor
Jump to solution

getting error with Set-Networkadapter

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".

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
9 Replies
LucD
Leadership
Leadership
Jump to solution

That should be a string, like this

-Networkname $_.Network


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
deensolea
Contributor
Contributor
Jump to solution

Sorry, but like this

-Networkname $(Set-NetworkAdapter $_.Network)

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

No, without the Set-NetworkAdapter, the NetworkName parameter expects a string, just the name.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
deensolea
Contributor
Contributor
Jump to solution

trying with this in the script

-Networkname ($_.Network)

getting error : New-VM : Parameter set cannot be resolved using the specified named parameters.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
deensolea
Contributor
Contributor
Jump to solution

thanks,

it works like charm and it only asks for confirmation before powering on. I believe a confirm-false would fix it.

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Strange, there is a -Confirm:$false on the Start-VM cmdlet.

And it still prompts?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
deensolea
Contributor
Contributor
Jump to solution

yes,

even strange is the set-network adapter function which won't work without get-network adapter

Reply
0 Kudos
Venom83
Enthusiast
Enthusiast
Jump to solution

"Set-NetworkAdapter" requires a confirmation. To suppress it, it also requires a "-confirm:$false"
Reply
0 Kudos