Created
May 26, 2019 06:55
-
-
Save MrAmbiG/ae2ea0c1ebdff983ba05479ed15ae0f5 to your computer and use it in GitHub Desktop.
L3Vmotion gateway setter for vmware esxi 6.x [courtesy : lucd]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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