<?xml version="1.0" encoding="UTF-8"?><!-- generator="wordpress/2.0.4" -->
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
	<title>Comments on: Windows PowerShell script for adding IP routes across a VPN</title>
	<link>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/</link>
	<description>Chris Hillman's random rants on IT stuff &#038; life</description>
	<pubDate>Mon,  6 Sep 2010 18:18:33 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.4</generator>

	<item>
		<title>by: SkullKiller</title>
		<link>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-24098</link>
		<pubDate>Tue, 09 Mar 2010 13:33:24 +0000</pubDate>
		<guid>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-24098</guid>
					<description>Hi.

Here is a ps1 script that takes the interface name, the ip to route and the ipmask and routes an ip trough a interface. It can be a vpn or a normal network card. It utilizes route.exe for route adding and .net for NIC IP determination. It also deletes a route.

param(
        [string] $InterfaceName = "Grupo Visabeira",
        [string] $IP2Route = "192.168.3.138",
        [string] $IPMask = "255.255.255.255",
        [SWITCH] $Delete)
#$delete = $true
IF ($Delete){
    $local:res = route delete $IP2Route
    IF ($local:res -match 'OK!'){"Route $IP2Route Deleted"}
    ELSE{"Error Deleting $IP2Route: $local:res"}
}else{
    [reflection.assembly]::LoadWithPartialName("System.Net") &#124; Out-Null
    $local:nic = [system.net.networkinformation.networkinterface]::GetAllNetworkInterfaces()&#124;Where-Object {$_.name -eq $InterfaceName}
    if ($local:nic.OperationalStatus -eq 'Up') {
        $local:interfaceIP = ($local:nic.GetIPProperties().unicastaddresses&#124;where {$_.ipv4Mask -ne '0.0.0.0'}).Address.IPAddressToString
        if ($local:interfaceIP) {
            $local:res = route add $IP2Route MASK $IPMask $interfaceIP
            IF ($local:res -match 'OK!'){"Interface [$InterfaceName] Connected and Route $IP2Route Added"}
            ELSE{"Error Adding $IP2Route in Interface $InterfaceName : $local:err"}
        }
    }else{"Network Interface [$InterfaceName] Not Connected"}
}</description>
		<content:encoded><![CDATA[<p>Hi.</p>
<p>Here is a ps1 script that takes the interface name, the ip to route and the ipmask and routes an ip trough a interface. It can be a vpn or a normal network card. It utilizes route.exe for route adding and .net for NIC IP determination. It also deletes a route.</p>
<p>param(<br />
        [string] $InterfaceName = &#8220;Grupo Visabeira&#8221;,<br />
        [string] $IP2Route = &#8220;192.168.3.138&#8243;,<br />
        [string] $IPMask = &#8220;255.255.255.255&#8243;,<br />
        [SWITCH] $Delete)<br />
#$delete = $true<br />
IF ($Delete){<br />
    $local:res = route delete $IP2Route<br />
    IF ($local:res -match &#8216;OK!&#8217;){&#8221;Route $IP2Route Deleted&#8221;}<br />
    ELSE{&#8221;Error Deleting $IP2Route: $local:res&#8221;}<br />
}else{<br />
    [reflection.assembly]::LoadWithPartialName(&#8221;System.Net&#8221;) | Out-Null<br />
    $local:nic = [system.net.networkinformation.networkinterface]::GetAllNetworkInterfaces()|Where-Object {$_.name -eq $InterfaceName}<br />
    if ($local:nic.OperationalStatus -eq &#8216;Up&#8217;) {<br />
        $local:interfaceIP = ($local:nic.GetIPProperties().unicastaddresses|where {$_.ipv4Mask -ne &#8216;0.0.0.0&#8242;}).Address.IPAddressToString<br />
        if ($local:interfaceIP) {<br />
            $local:res = route add $IP2Route MASK $IPMask $interfaceIP<br />
            IF ($local:res -match &#8216;OK!&#8217;){&#8221;Interface [$InterfaceName] Connected and Route $IP2Route Added&#8221;}<br />
            ELSE{&#8221;Error Adding $IP2Route in Interface $InterfaceName : $local:err&#8221;}<br />
        }<br />
    }else{&#8221;Network Interface [$InterfaceName] Not Connected&#8221;}<br />
}
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Mick</title>
		<link>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-15738</link>
		<pubDate>Fri, 08 May 2009 02:23:44 +0000</pubDate>
		<guid>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-15738</guid>
					<description>Hi mate,

Any idea how to automatically execute that script after a connection has been established to the VPN?</description>
		<content:encoded><![CDATA[<p>Hi mate,</p>
<p>Any idea how to automatically execute that script after a connection has been established to the VPN?
</p>
]]></content:encoded>
				</item>
	<item>
		<title>by: Eugen</title>
		<link>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-10871</link>
		<pubDate>Tue, 13 Jan 2009 05:40:34 +0000</pubDate>
		<guid>http://www.webboise.com/windows-powershell-script-for-adding-ip-routes-across-a-vpn/#comment-10871</guid>
					<description>Great article.  just what i was looking for.</description>
		<content:encoded><![CDATA[<p>Great article.  just what i was looking for.
</p>
]]></content:encoded>
				</item>
</channel>
</rss>
