Hi ,
I have a requirement to move VMs from one esxi to other esxi with Move-VM but unable to figure out if we have more NICs on VM like 3 , 4 , 5 ,6 NICs , is it possible to move to right adapter to right port group. below is the script in my mind kindly help.
$networkAdapter = Get-NetworkAdapter -vm VMname
if ($networkAdapter.Count -ge 1) {
foreach ( $nadapter in $networkAdapter) {
$destinationPortGroup = Get-VDPortgroup -VDSwitch 'NewvDS' -Name "$($nadapter.NetworkName)-new"
Move-VM -VM VMname -Destination Esxiserver -NetworkAdapter $nadapter -PortGroup $destinationPortGroup -WhatIf
}
}
You could try something like this
$vNic = Get-NetworkAdapter -VM VMname
$pg = $vNic | %{Get-VirtualPortGroup -Name "$($_.NetworkName)-new"}
Move-VM -VM VMName -Destination Esxiserver -NetworkAdapter $vNic -PortGroup $pg
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
The Move-VM cmdlet parameters NetworkAdapter and Portgroup both accept an array of values.
That allows you to specify per vNIC to which destination portgroup they shall be moved.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could you please help with sample code to test from my end. Thank you in advance.
You could try something like this
$vNic = Get-NetworkAdapter -VM VMname
$pg = $vNic | %{Get-VirtualPortGroup -Name "$($_.NetworkName)-new"}
Move-VM -VM VMName -Destination Esxiserver -NetworkAdapter $vNic -PortGroup $pg
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference