VMware Cloud Community
pacifierzWBG
Contributor
Contributor
Jump to solution

Is it possible to change both host and datastore on powered-on VM using PowerCLI like we do in Web-Client

I have a requirement to perform online migration of 100+ Powered-on VMs from one cluster to another without shared storage.

I know that we can do it through Web-Client, but is it possible using PowerCLI.

Can the below steps be done on powered-on VMs using PowerCLI script? Please help

Step 1: Select change both compute resource and storage

pastedImage_0.png

Step 2: Select the destination host/cluster

Step 3: Select the datastore

Step 4: Select the network

pastedImage_1.png

http://www.vmwarealert.com/
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Yes, that should be possible.

Try like this

$vmName = 'MyVM'

$esxName = 'TgtEsx'

$dsName = 'TgtDatastore'

$pgName = 'TgtPortgroup'


$vm = Get-VM -Name $vmName

$pg = Get-VirtualPortGroup -Name $pgName

Move-VM -VM $vm -Destination $esxName -Datastore $dsName -PortGroup $pg -Confirm:$false


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

View solution in original post

0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, that should be possible.

Try like this

$vmName = 'MyVM'

$esxName = 'TgtEsx'

$dsName = 'TgtDatastore'

$pgName = 'TgtPortgroup'


$vm = Get-VM -Name $vmName

$pg = Get-VirtualPortGroup -Name $pgName

Move-VM -VM $vm -Destination $esxName -Datastore $dsName -PortGroup $pg -Confirm:$false


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

0 Kudos
pacifierzWBG
Contributor
Contributor
Jump to solution

Hi LucD,

Thanks for your response.

It is working fine for single VM.

But when i try run for multiple VMs i get an error.. Can you please help?

contents of "servers.csv"

name,host,datastore,portgroup

vm1,esx1,ds1,pg1

vm2,esx2,ds2,pg2

vm3,esx3,ds3,pg3

vm4,esx4,ds4,pg4

$vms = Import-CSV C:\Script\servers.csv

foreach ($vm in $vms){

$VMname = Get-VM -Name $vm.name

$VMhost = Get-VMHost $vm.host

$Datastore = Get-Datastore $vm.datastore

$PGname = Get-VirtualPortGroup -Name $vm.portgroup

Move-VM -VM $VMname -Destination $VMhost -Datastore $Datastore -PortGroup $PGname -Confirm:$false

}

pastedImage_3.png

http://www.vmwarealert.com/
0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is a timeout (the default of 300 seconds or 5 minutes).
Could be caused by many factors.

Try increasing the timeout with the Set-PowerCLIConfiguration cmdlet and the WebOperationTimeoutSeconds parameter.


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

0 Kudos
pacifierzWBG
Contributor
Contributor
Jump to solution

Hi LucD,

It worked. Thanks for your help.

http://www.vmwarealert.com/
0 Kudos