We help IT Professionals succeed at work.

ESXi and PowerCLI

jmachado81
jmachado81 asked
on
92 Views
Last Modified: 2018-05-24
I have created a 2 node vsan cluster with a witness.  The two physical hosts are interconnected with 10gb links and the vsan vmkernel resides on that particular vswitch.  I leave the mgmt on the default vSwitch0 which uses vmk0.

I'm looking for a way to script in powercli/powershell adding a route to the esxi hosts so that it can communicate with the witness.

$HostNameFQDN = xyz.domain.com

This outputs nothing on my system currently but it seems like i'm really close.
$Host_Gateway = Get-VMHost -Name $HostNameFQDN | Get-VMHostNetworkAdapter | select VMKernelGatway

New-VMHostRoute -VMHost $HostNameFQDN -Destination 172.23.0.0 -Gateway $Host_Gateway -PrefixLength 20

Would somebody be able to assist with getting this to work, correctly?  I've also noticed that the Get-network commands do not work in Powershell ISE but they do in the regular powershell window.

Thanks in advance.
Comment
Watch Question

PberSolutions Architect
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
How can I pull the existing gateway from the vmk0 VMKernel (mgmt)?  When i run the below the output is blank.

Get-VMHost -Name $HostNameFQDN | Get-VMHostNetworkAdapter | select VMKernelGatway
PberSolutions Architect
CERTIFIED EXPERT

Commented:
Try this:

Get-VMHost -Name $HostNameFQDN | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select VMKernelGateway
Solutions Architect
CERTIFIED EXPERT
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Author

Commented:
This displays all vmkernels instead of just vmk0 but I'll push this line up in my script so there is only one vmk at the time of running.  Thanks
Qlemo"Batchelor", Developer and EE Topic Advisor
CERTIFIED EXPERT
Top Expert 2015

Commented:
The above script works, but is "wrong" in it doing too much. A simple
$Host_Gateway = Get-VMHost -Name $HostNameFQDN | Get-VMHostNetwork | Select VMKernelGateway

Open in new window

is sufficient. The main point has been exchanging Get-VMHostNetworkAdapter by Get-VMHostNetwork.