Skip to content

Instantly share code, notes, and snippets.

@MrAmbiG
Created May 26, 2019 06:55
Show Gist options
  • Save MrAmbiG/ae2ea0c1ebdff983ba05479ed15ae0f5 to your computer and use it in GitHub Desktop.
Save MrAmbiG/ae2ea0c1ebdff983ba05479ed15ae0f5 to your computer and use it in GitHub Desktop.
L3Vmotion gateway setter for vmware esxi 6.x [courtesy : lucd]
Write-Host "make sure you are connected to a vcenter first"
$cluster = Read-Host "cluster name?"
$vmhosts = Get-Cluster $cluster | Get-VMHost | sort
$stackName = 'vmotion'
$ipGateway = Read-Host "default gateway?"
$ipDevice = Read-Host "vmk device?" # ex: vmk2
forech $VMHost in $vmhosts {
$esx = Get-VMHost -Name $VMHost
$netSys = Get-View -Id $esx.ExtensionData.ConfigManager.NetworkSystem
$stack = $esx.ExtensionData.Config.Network.NetStackInstance | where{$_.Key -eq $stackName }
$config = New-Object VMware.Vim.HostNetworkConfig
$spec = New-Object VMware.Vim.HostNetworkConfigNetStackSpec
$spec.Operation = [VMware.Vim.ConfigSpecOperation]::edit
$spec.NetStackInstance = $stack
$spec.NetStackInstance.ipRouteConfig.defaultGateway = $ipGateway
$spec.NetStackInstance.ipRouteConfig.gatewayDevice = $ipDevice
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment