VMware Cloud Community
fborges555
Enthusiast
Enthusiast

VM portgroup to another portgroup

HI gurus

I need to change around 100 VM from one portgroup to another portgroup, is this possible using PowerCLI

Thanks in advance

0 Kudos
5 Replies
LucD
Leadership
Leadership

With Get-NetworkAdapter and Set-NetworkAdapter


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

0 Kudos
fborges555
Enthusiast
Enthusiast

L.

Thanks I got this far, do you think i am in the right direction

$vm='myvmtomove'

$destination='myesxihost'

$Datastore='myDatastore'

$destinationPortG='PortgroupLabel'

$networkadapter=get-networkadapterr -VM $vm

move-vm $vm -destination $destination -networkadapter $networkadapter -portgroup $destinationPortG -datastore $datastore

this will move the vm to another esxi host on a different cluster and change the VLAN ID for destination and datastore also as well

let me know if I am close

0 Kudos
LucD
Leadership
Leadership

I thought you just wanted to change the Portgroup for each VM.

Not sure why the Move-VM is there?


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

0 Kudos
fborges555
Enthusiast
Enthusiast

L.

My bad on making this clear

I have vms that I want to move them from one cluster to another new cluster within the same data center , also I would like to move them to a new datastore and to a new portgroup within the new cluster , I thought I could use the move-vm to accomplish this as I used this move-vm to move between cluster and different datastore, I hope I make sense now.

Thanks

0 Kudos
LucD
Leadership
Leadership

Ok, can you try something like this?

$fromCluster = 'oldCluster'

$toCluster = 'newCluster'

$newDatastore = 'newDatastore'

$newPortgroup = 'newPortgroup'


Get-Cluster -Name $fromCluster | Get-VM |

ForEach-Object -Process {

    Move-VM -VM $_ -Datastore $newDatastore -PortGroup $newPortgroup -Destination $toCluster -Confirm:$false

}


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

0 Kudos