«

»

Verify vMotion functionality using PowerCLI

One very important thing during any environment deployment or environment expansion is to verify it actually works as expected.

It has been a while since my last script blog post but i wanted to share one PowerCLI script i put together a while ago to verify vSphere vMotion functionality. The script has been very handy and especially when you deploy many Nutanix Nodes/ESXi hosts the same time you do not want to waste time to manually verify you can run vMotion between every Nutanix Nodes/ESXi hosts.

The script that vMotion a VM between all (or specified ESXi hosts) were tested using the following software versions:

  • VMware vCenter Server 6.0
  • VMware ESXi 6.0
  • VMware PowerCLI 6.3 R1
  • Nutanix AOS 4.7.0.1

As usual, change the red marked text to your required/specific values.

#

# PowerCLI to test vMotion functionality
# Version 1.0
# Magnus Andersson – Staff Solution Architect @Nutanix
#
# Specify vCenter Server, vCenter Server username, vCenter Server user password, esxi hosts and the VM you wish to vMotion.
$vCenter=”vc01.vcdx56.local
$vCenterUser=”a_magnus@vcdx56.local
$vCenterUserPassword=”notsecret
$esxihosts=”*
$vm=”NCLX01-VM01
#
#
#Connect to vCenter Server
write-host “Connecting to vCenter Server $vCenter” -foreground green
Connect-viserver $vCenter -user $vCenterUser -password $vCenterUserPassword -WarningAction 0 | out-null
#
# Perform vMotion actions
write-host ————-
write-host Starting the vMotion process of VM $vm
foreach ($esxihost in (get-vmhost $esxihosts | ? { $_.ConnectionState -eq “Connected”} |sort))
{ Get-VM -Name $vm | Move-VM -Destination $esxihost | out-null
}
write-host ————-
write-host The vMotion process is complete
write-host ————-
# Disconnect from vCenter Server
write-host “Disconnecting to vCenter Server $vCenter” -foreground green
disconnect-viserver -confirm:$false | out-null
Below is the script output when running in my lab environment.
vMotion

This is the very limited output since i’m using out-null after the commands. However, if you receive an error it will be displayed in red text. If you want additional input (will be quite a lot) just remove the out-null