powershell - How to use New-NetRoute without specifying the InterfaceIndex? -


as know, can set routing in windows via

route add xxx.xxx.xxx.xxx mask yyy.yyy.yyy.yyy zzz.zzz.zzz.zzz 

and os decides interface use. now, want in powershell command

new-netroute –destinationprefix "xxx.xxx.xxx.xxx/yy" –interfaceindex w –nexthop zzz.zzz.zzz.zzz 

the problem here interfaceindex mandatory here, want os figure out (as in first command). how can this?

never played myself there cmdlet serve purpose of looking for. called find-netroute , finds best local ip address , best route reach remote address. information returned netipaddress object , netroute object. both should contain system chosen index. supported on windows server 2012 r2 , windows 8.1 currently.

a simple use provide remote address. following code return interfaceindex variable $bestindex use new-netroute

$bestindex = find-netroute -remoteipaddress "123.456.789.012" | select -first 1  -expandproperty interfaceindex  new-netroute –destinationprefix "xxx.xxx.xxx.xxx/yy" –interfaceindex $bestindex –nexthop zzz.zzz.zzz.zzz 

i encourage read more on technet page linked. found reading on how new-netroute worked.


Comments

Popular posts from this blog

How to provide Authorization & Authentication using Asp.net, C#? -

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

How to use Authorization & Authentication in Asp.net, C#? -