Quantcast
Channel: VMware Communities: Message List
Viewing all articles
Browse latest Browse all 228535

Re: move-vm script placing port groups on wrong adapters for VMs with multiple nics

$
0
0

If this statement in the article is true I think this may work

"One key thing to note is that the first item in each array will be referenced together, then the second items will be referenced together, and so on and so forth"

 

$sourcehostVMS= get-vm -Server $sourcevcenter | where name -Match wiery-test

 

 

$nic1='Network adapter 1'

$nic2='Network adapter 2'

$nic3='Network adapter 3'

$nic4='Network adapter 4'

 

 

foreach ($vm in $sourcehostVMS){

$networkadapters=@()

$networkadapters=Get-NetworkAdapter -vm $vm

$networkadapters | Format-Table -AutoSize

 

$destinationPortgroup=@()

if ($networkadapters.name -eq $nic1){$destinationPortgroup += Get-VirtualPortGroup -Server $destinationvcenter -Name (Get-NetworkAdapter -VM $vm | where name -EQ $nic1).NetworkName}

if ($networkadapters.name -eq $nic2){$destinationPortgroup += Get-VirtualPortGroup -Server $destinationvcenter -Name (Get-NetworkAdapter -VM $vm | where name -EQ $nic2).NetworkName}

if ($networkadapters.name -eq $nic3){$destinationPortgroup += Get-VirtualPortGroup -Server $destinationvcenter -Name (Get-NetworkAdapter -VM $vm | where name -EQ $nic3).NetworkName}

if ($networkadapters.name -eq $nic4){$destinationPortgroup += Get-VirtualPortGroup -Server $destinationvcenter -Name (Get-NetworkAdapter -VM $vm | where name -EQ $nic4).NetworkName}

$destinationPortgroup | Format-Table -AutoSize

 

 

$SourceDatastore=(get-vm $vm -Server $sourcevcenter | get-datastore).name

$destinationDatastore=(Get-Datastore -Name $SourceDatastore -Server $destinationvcenter).name

 

 

Move-VM -VM $vm -Server $destinationvcenter -Destination $destinationhost -Datastore $destinationDatastore -NetworkAdapter $networkadapters -PortGroup $destinationPortgroup}


Viewing all articles
Browse latest Browse all 228535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>