• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 52
  • Last Modified:

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 -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.
  • 3
  • 2
2 Solutions
PberSolutions ArchitectCommented:
Your syntax looks good, but looks like you need to assign it to a object and then perform a Set:

$vmhostroute = New-VMHostRoute -VMHost $HostNameFQDN -Destination -Gateway $Host_Gateway -PrefixLength 20

Set-VMHostRoute -VMHostRoute ($vmhostroute) -Destination 20
jmachado81Author 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 ArchitectCommented:
Try this:

Get-VMHost -Name $HostNameFQDN | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select VMKernelGateway
Worried about phishing attacks?

90% of attacks start with a phish. It’s critical that IT admins and MSSPs have the right security in place to protect their end users from these phishing attacks. Check out our latest feature brief for tips and tricks to keep your employees off a hackers line!

PberSolutions ArchitectCommented:
So for your original question:
$Host_Gateway = Get-VMHost -Name $HostNameFQDN | Get-VMHostNetwork | Select Hostname, VMKernelGateway -ExpandProperty VirtualNic | Select VMKernelGateway
jmachado81Author 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
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now