Link to home
Start Free TrialLog in
Avatar of jmachado81
jmachado81

asked on

ESXi and PowerCLI

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.
SOLUTION
Avatar of Pber
Pber
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jmachado81
jmachado81

ASKER

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
Try this:

Get-VMHost -Name $HostNameFQDN | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select VMKernelGateway
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.