VMware Cloud Community
jvm2016
Hot Shot
Hot Shot
Jump to solution

gettingiproutes_and_creatingstaticroutes_powercli

Hi Luc,

i thought of starting a new discussion associated  below thred 

creating vmkernel port group_powercli

vmkernel ports for replication has already been created and assigned to replication vlan as per above post. .

created following function that will  find iproute on each esxi host of a cluster and at the same time add new static route to each esxi in same cluster.

can you please validate the orange part of the code .(whether datatype string is correct ?

function get-staticroute {

   [cmdletbinding()]

   param(

   [Parameter(Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]

   [string]$clustername,

   [Parameter(Mandatory=$true)]

        [string]$destinationnetwork,

        [Parameter(Mandatory=$true)]

        [string]$prefixlength,

        [Parameter(Mandatory=$true)]

        [string]$gateway

  

   )

  

  

   #$clustername=read-host "clustername"

  

   $cluster=get-cluster $clustername

   $vmhosts=get-vmhost -location $cluster

   $fragments = @()

   foreach($vmhost in $vmhosts)

   {

   $esxcli = Get-EsxCli -VMHost $vmhost -V2

   $staticrouteinfo=$esxcli.network.ip.route.ipv4.list.Invoke()

   $fragments += $vmhost.name

   $fragments += $staticrouteinfo

 

   }

   $fragments

   $newstaticroute=read-host "would yu like to add static route to all esxi in cluster"

   if($newstaticroute -eq 'y')

   {

   foreach($h in $vmhosts)

   {

   #New-VMHostRoute -vmhost $h -destination 172.16.9.0 -PrefixLength 25 -Gateway 172.16.9.1 -WhatIf

   New-VMHostRoute -vmhost $h -destination $destinationnetwork  -PrefixLength $prefixlength  -Gateway $gateway -WhatIf

   }

   }

   }

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You can do something like this

$route = @{

   network = "$destinationnetwork/$prefixlength"

   gateway = $gateway

}

$esxcli.network.ip.route.ipv4.add.Invoke($route)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
4 Replies
LucD
Leadership
Leadership
Jump to solution

Yes, that should work.

Just wondering why you don't use $esxcli as well for creating the new route?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

can yu suggest that way also?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do something like this

$route = @{

   network = "$destinationnetwork/$prefixlength"

   gateway = $gateway

}

$esxcli.network.ip.route.ipv4.add.Invoke($route)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
jvm2016
Hot Shot
Hot Shot
Jump to solution

thnaksLuc.

Reply
0 Kudos