Can anyone help me figure out how to set this value from powercli or esxcli?
Try something like this.
Update the variables in the first 4 lines to correspond with your environment
$esxName = 'MyEsx'
$stackName = 'vmotion'
$ipGateway = '192.168.1.254'
$ipDevice = 'vmk1'
$esx = Get-VMHost -Name $esxName
$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.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig
$route = New-Object VMware.vim.HostIpRouteConfig
$route.defaultGateway = $ipGateway
$route.gatewayDevice = $ipDevice
$spec.NetStackInstance.ipRouteConfig = $route
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Try something like this.
Update the variables in the first 4 lines to correspond with your environment
$esxName = 'MyEsx'
$stackName = 'vmotion'
$ipGateway = '192.168.1.254'
$ipDevice = 'vmk1'
$esx = Get-VMHost -Name $esxName
$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.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig
$route = New-Object VMware.vim.HostIpRouteConfig
$route.defaultGateway = $ipGateway
$route.gatewayDevice = $ipDevice
$spec.NetStackInstance.ipRouteConfig = $route
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hey Luc,
can an we use this methof to update other tcp stack settings like dns and search domains?
Yes, on the HostNetStackInstance object, you can specify under the DnsConfig property, a HostDnsConfig object, you can specify several DNS settings
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc,
I‘ve almost completed my new host build script I just want to fine tune it a little. Currently to use the motion tcp stack for vmotion portgroups I’m using esxcli to enable the vmotion stack and create vmotion portgroups using the vmotion stack, then migrating the portgroups to DVS because my understanding is the esxcli method doesn’t work directly against DVS, however this was discussed a couple of weeks back and anothe option was to use the api. Can you can this api method works on DVS becaue if so I would prefer to set it directly on the DVS and potentially the possibility of writing a function / module for this?
Hi Luc,
So tested this out and it failed unfortunately. I pre-created the portgroup on the default TCP/IP stack on VMK1 then ran this....
S C:\Users\user>> $esxName = 'esx.host.com'
$stackName = 'vmotion'
$ipGateway = '10.42.228.254'
$ipDevice = 'vmk1'
$esx = Get-VMHost -Name $esxName
$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.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig
$route = New-Object VMware.vim.HostIpRouteConfig
$route.defaultGateway = $ipGateway
$route.gatewayDevice = $ipDevice
$spec.NetStackInstance.ipRouteConfig = $route
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
Exception calling "UpdateNetworkConfig" with "2" argument(s): "An error occurred during host configuration. Operation failed, diagnostics report: Unable to Get Instance List: Sysinfo error: FailureSee VMkernel log for details."
At line:20 char:1
+ $netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode] ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : VimException
Setting DNS only seems to work for the defaultTcpipStack, not for vmotion, nor for Provisioning.
For the defaultTcpipStack it works like this
$esxName = 'esx1.local.homelab'
$stackName = 'defaultTcpipStack'
$dnsServers = '192.168.1.200','192.168.1.201'
$domainName = 'local.homelab'
$hostName = 'esx1'
$esx = Get-VMHost -Name $esxName
$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.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig
$dns = New-Object VMware.Vim.HostDnsConfig
$dns.Address = $dnsServers
$dns.Dhcp = $false
$dns.HostName = $hostName
$dns.DomainName = $domainName
$dns.SearchDomain = $domainName
$spec.NetStackInstance.DnsConfig = $dns
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc,
I managed to get what i needed working
How were you able to create the vmotion stack and then migrate the portgroups to DVS?
@lucd
I was wondering how can i customise this $esxName variable to include multiple esxi hosts. I have approx 120+ esxi which needs to have vmotion gateways 😞 😞
One way is to place all the names in an array, and then do a ForEach loop over that array.
Something like this
$stackName = 'defaultTcpipStack'
$dnsServers = '192.168.1.200','192.168.1.201'
$domainName = 'local.homelab'
$hostName = 'esx1'
foreach($esxName in $esxNames){
$esx = Get-VMHost -Name $esxName
$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.RouteTableConfig = New-Object VMware.Vim.HostIpRouteTableConfig
$dns = New-Object VMware.Vim.HostDnsConfig
$dns.Address = $dnsServers
$dns.Dhcp = $false
$dns.HostName = $hostName
$dns.DomainName = $domainName
$dns.SearchDomain = $domainName
$spec.NetStackInstance.DnsConfig = $dns
$config.NetStackSpec += $spec
$netsys.UpdateNetworkConfig($config,[VMware.Vim.HostConfigChangeMode]::modify)
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
you are a Magician @Lucd .
Hello,
One remark: This loop will set the same hostName for all ESXi servers (!)
Regards,
Wojtek
You are correct, thanks for noticing,
That line should have said
$dns.HostName = $esxName
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference