$lists = @(
[pscustomobject]@{vmname=‘xxxcc’;descluster=‘xxxxxx’;desdatastore=‘xxxxxx’}
)
foreach ( $list in $lists ){
$VM = Get-VM $list.vmname
$VMAdapters = $VM | Get-NetworkAdapter
$deshost = (Get-Cluster $list.descluster | Get-VMHost | Sort-Object -Property MemoryUsageGB)[0]
$desvdswitch = $deshost | Get-VDSwitch
#$sourcenetworkAdapter = @()
$destinationPortGroup = @()
foreach($VMAdapter in $VMAdapters){
$tempDesPortGroupName = $VMAdapter.NetworkName.split(“_”)[-1]
$tempDesAdapter = d e s v d s w i t c h ∣ G e t − V D P o r t g r o u p − N a m e ∗ desvdswitch | Get-VDPortgroup -Name * desvdswitch∣Get−VDPortgroup−Name∗($tempDesPortGroupName)
#$sourcenetworkAdapter += $VMAdapter
$destinationPortGroup += $tempDesAdapter
}
$desdatastore = Get-Datastore $list.desdatastore | where { $_.Uid -like ‘vcname’}
$VM | Move-VM -Destination $deshost -NetworkAdapter $VMAdapters -PortGroup $destinationPortGroup -RunAsync -Datastore $desdatastore
}