I created several VMs using:
New-VM -Name $NewVMName -Host (Get-VMHost -Datastore $datastore)[0] -GuestId $VMGuestOS -Datastore $datastore -MemoryMB $RAM -Floppy -CD -DiskMB $disk -ResourcePool $respool -Location $folder
This creates the VM with a vmxnet network adapter instead of flexible and when we install RHEL5 on it it won't see the NIC.
How can one specify to use the default Flexible NIC?
It looks indeed as if the New-VM cmdlet doesn't take the GuestID into account like the VI Client does.
As a solution one can use a function based on the ReconfigVM method of the VirtualMachine object.
I have implemented the function as a filter since this allows one to pipe the newly created guest to the filter.
filter set-nicsflexible{ $vm = Get-View $_.ID $i = 0 foreach($dev in $vm.Config.Hardware.Device){ if (($dev.GetType()).Name -eq "VirtualVmxnet"){ $spec = new-object VMware.Vim.VirtualMachineConfigSpec $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.DeviceChange[$i].device = New-Object VMware.Vim.VirtualPCNet32 $spec.DeviceChange[$i].device.Backing = $dev.Backing $spec.DeviceChange[$i].device.Connectable = $dev.Connectable $spec.DeviceChange[$i].device.DeviceInfo = $dev.DeviceInfo $spec.DeviceChange[$i].device.key = $dev.Key $spec.DeviceChange[$i].operation = "edit" $i++ } } if ($i -gt 0) {$vm.ReconfigVM($spec)} }
The filter can be used like this
New-VM -Name <VM-name> -GuestId rhel5Guest -VMHost <VM-host> | set-nicsflexible
Some notes:
1) the filter will convert all NICs of the newly created guest from vmxnet to flexible
2) the script could be used in a similar way to change the NIC to any of the other available types
3) the code is attached
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
It looks indeed as if the New-VM cmdlet doesn't take the GuestID into account like the VI Client does.
As a solution one can use a function based on the ReconfigVM method of the VirtualMachine object.
I have implemented the function as a filter since this allows one to pipe the newly created guest to the filter.
filter set-nicsflexible{ $vm = Get-View $_.ID $i = 0 foreach($dev in $vm.Config.Hardware.Device){ if (($dev.GetType()).Name -eq "VirtualVmxnet"){ $spec = new-object VMware.Vim.VirtualMachineConfigSpec $spec.DeviceChange += New-Object VMware.Vim.VirtualDeviceConfigSpec $spec.DeviceChange[$i].device = New-Object VMware.Vim.VirtualPCNet32 $spec.DeviceChange[$i].device.Backing = $dev.Backing $spec.DeviceChange[$i].device.Connectable = $dev.Connectable $spec.DeviceChange[$i].device.DeviceInfo = $dev.DeviceInfo $spec.DeviceChange[$i].device.key = $dev.Key $spec.DeviceChange[$i].operation = "edit" $i++ } } if ($i -gt 0) {$vm.ReconfigVM($spec)} }
The filter can be used like this
New-VM -Name <VM-name> -GuestId rhel5Guest -VMHost <VM-host> | set-nicsflexible
Some notes:
1) the filter will convert all NICs of the newly created guest from vmxnet to flexible
2) the script could be used in a similar way to change the NIC to any of the other available types
3) the code is attached
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Kudos to you, works like a charm!
Thank you for sharing.
Thanks, this was what I was looking for!
Just wanted to also mention/confirm that this will be a lot easier in our upcoming 1.0 GA release, you will be able to control the adapter type by either setting the guest OS type, which will give you the same type you get when you use the VI Client, and also we will be enhancing new-networkadapter to allow specifying the adapter type.
Hi Carter,
Sounds like great news! Any idea about the release date?