[Script]: Enable/Disable vMotion on VMKernel Ports via PowerCLI
vMotion is a core VMware technology that allows live migration of virtual machines between ESXi hosts without downtime. This capability is essential for maintenance tasks, disaster recovery, and workload balancing. Enabling it on multiple ESXi servers can be done manually through the vSphere Client, but for efficiency and automation, PowerCLI shines.
Enabling vMotion on VMKernel Ports via PowerCLI
You maybe have to disable or enable vMotion traffic on some VMKernel ports on ESXi for doing some maintenance tasks. Disabling or enabling takes lot of time for many servers in datacenter. You can disable or enable via PowerCLI by run a simple script.
The below script will enable vMtion for all ESXi hosts on a vCenter:
Get-VMHost | Get-VMHostNetworkAdapter -Name (VMKernel Port Name) |Set-VMHostNetworkAdapter -VMotionEnabled $true
Note: Change “VMKernel Port Name” with specific VMKernel port on your ESXi servers. Change “$true” to “$false” for disabling.
You can find VMKernel ports for specific ESXi hosts or all the ESXi hosts with the below scripts:
Get-VMHost (Host Name or Host IP) | Get-VMHostNetworkAdapter -VMKernel
Note: Remove “Host Name or Host IP” to list all ESXi servers’ VMKernel ports.
If you want to disable or enable on ESXi hosts within cluster, you can use the below script:
$ESXi_Hosts=Get-Cluster -Name Cluster1 | Get-VMHost ForEach ($ESXi_Host in $ESXi_Hosts) { Get-VMHost $ESXi_Host | Get-VMHostNetworkAdapter -Name vmk0 |Set-VMHostNetworkAdapter -VMotionEnabled $true }
Note: Change Cluster1 with your cluster name and also if you want disabling vMotion, replace $true with $false.
After enabling on all ESXi servers, verify its functionality. You can use the vSphere Client or PowerCLI to initiate test migrations between hosts and monitor their progress.
By leveraging PowerCLI’s automation capabilities, enabling it on multiple ESXi servers becomes a streamlined and efficient process, saving time and ensuring consistent configuration across your virtualized environment.
Further Reading
Java.net.SocketException: No buffer space available – VMware View Connection Server
Update VMware Tools Automatically
Run ESXi Commands Via PowerShell And SSH
[Script]: Check Time Synchronization with Host on Virtual Machines – PowerCLI
[PowerCLI]: Add Local Administrator Account on ESXi
[PowerCLI]: ESXi Syslog Configuration via PowerCLI
[How To]: ESXi Installation Stopped – partedUtil Failed
[Script]: Find ESXi HBA WWN via PowerCLI
External Links
What is vMotion? | Live Migration of Virtual Machines | VMware