Techie solution
asked on
How to automate Powershell scripts for Vmware migration?
hi i want to automate my vm migration from one cluster to another via powershell. please help me throgh . Also please guide me how can i include vmware cli in powershell.
ASKER
I have to move vm across the cluster.
With the above code, you can gracefully shutdown the virtual machines and you can move across datacenters.
ASKER
#Put the path of the csv file
$vms = Import-CSV "C:\test\3.csv"
foreach ($vm in $vms)
{
#Assign Variables
$VMName = ($vm.Name1,$vm.Name2,$vm.Name3,$vm.Name4,$vm.Name5, $vm.Name6,$vm.Name7,$vm.Name8, $vm.Name9,$vm.Name10)
$vHost = $vm.Hos
$vDatastore = $vm.Datastore
$vNetwork = $vm.Network
#Power off vms
Get-VM -Name $VMName | Shutdown-VMGuest
#Where the VM gets Migrated (Datastore:VV02-FC-D01;VV02-FC-D02;VV02-FC-D03;VV02-FC-D04,VV02-FC-D01 to D04)
#Host is XXXXXXXXX017 to XXXXXXXX0024, XXXXXXXX0025 to XXXXXXX0032)
Move-VM -VM $VMName -Destination $vHost -Datastore $vDatastore
#Set Network Adapter (NET_10.xx.xx.0_24 to NET_NET_10.xx.xx.0_24,NET_10.xx.xx.0_24)
Get-VM -Name $VMName|Get-NetworkAdapter| Set-NetworkAdapter -NetworkName $vNetwork -Confirm:$false
#Power On VMs
Start-VM $VMName -Confirm -RunAsync
}
ASKER
I have Tried above script but network script is not working. it is throwing error network is not accessible.
ASKER
please help me with this.
Did you check that the assigned network of the VM on the source host is also defined for the destination host?
ASKER
No, what would be the format to change the network during migration
Vmotion VMKernel Port Group should have same (label) name at both source and destination network.
ASKER
It is different on different dvswitch
Is there a separate Distributed switch for each cluster?
ASKER
The new infra on same vcenter has different DVSwith
I guess you will have to set up a "fake" DV switch on the new infrastructure just for the migration, and then change the DV switch in the migrated VMs.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can move multiple virtual machines to an ESX server via below code. If you have shared storage between the source and destination host you can comment out the shutdown line.
You can add a snap-in to Powershell to load the PowerCLi commands i.e Add-PSSnapin Vmware.Vimautomation.core -- type this in Powershell.
Code:
Open in new window
Please let me know if this is helpful.