Thanks to my college Sebastian, here his linkedin profile , I have an opportunity to post very nice PowerCLI script. Script do vMotion VM between clusters \ vDS switches and storage.
What script does:
- Import list of the virtual machines to migrate
- reconfigure VM to use standard switch
- migrate VM to new cluster
- reconfigure VM to use new vDS switch and portgroup on new cluster
[box type=”info”]
- variable $vCenter is not needed when you work only with one vCenter server
- clusters belongs to different virtual distributed switches
- storage between clusters isn’t shared
[/box]
#Author: Sebastian Barylo #general scope variables, customize migration targets (vhost, datastore, portgroup)if needed $batch_input = "<path to input file>" $vCenter = 'vc01.lab.local' $target_vhost = Get-vmhost -name esx02.lab.local -server $vCenter $target_datastore = get-datastore -name DS01 -server $vCenter $target_pg = get-vdswitch -name DV01 -server $vCenter | get-vdportgroup -name 'PG-01' -server $vCenter #load names of vms to be processed from file $vm_names = Get-Content $batch_input #for each name, retrieve vm object and process it foreach ($vm_name in $vm_names) { $vm = get-vm -name $vm_name -server $vCenter #reconfigure vnic to standard vswitch to enable migration get-networkadapter -vm $vm -name "Network adapter 1" -server $vCenter | set-networkadapter -networkname 'VM Network' -connected:$false -confirm:$false| Out-Null #(s)vmotion the vm move-vm -vm $vm -destination $target_vhost -datastore $target_datastore -server $vCenter | Out-Null #retrieve the vm object again and connect it to target vdswitch, set-networkadapter is invoked twice #because it doesn't seem to allow connecting to vdswitch and changing link state to "connected" in one go (bug?) get-vm -name $vm_name -server $vCenter | get-networkadapter -name "Network adapter 1"| set-networkadapter -connected:$true -confirm:$false| set-networkadapter -portgroup $target_pg -confirm:$false| Out-Null Write-Host "$vm_name --!!!DONE!!!---" }
Hi Artur,
can I use your script to vmotion VMs between 2 vcenters using vDS? When I tried to
migrate VM, powershell says that move-vm is supported only on one VI-Server.
I will explain my situation: due to several upgrades, my vCenter db performs bad, so I
decided
to start almost from scratch.I have deployed a new vCenter, now I am
trying copy VI structures (vm folders, roles, etc..) and than migrate VMs –
they are using vDS
Rostislav