Perform a VMotion on multiple virtual machines using PowerCLI
- Connect to vCenter Server:
Connect-VIServer -Server vCenterServer -User username -Password password
- Initiate VMotion for each VM: Loop through the array and use the
Move-VM
cmdlet to perform the VMotion.foreach ($vmName in $vmNames) {
$vm = Get-VM -Name $vmName
$destinationHost = “DestinationHost” # Replace with the target host’s name or IP address
$destinationDatastore = “DestinationDatastore” # Replace with the target datastore’s nameMove-VM -VM $vm -Destination (Get-VMHost -Name $destinationHost) -Datastore (Get-Datastore -Name $destinationDatastore) -Priority High
}
- For Multiple VM, Store VM names in an array: Create an array containing the names of the virtual machines you want to VMotion.
$vmNames = @(“VM1”, “VM2”, “VM3”)