Internet Toggle

Created by Andrew Schott, Modified on Thu, Jun 10, 2021 at 12:16 AM by Andrew Schott

<#


.Synopsis


   Toggle internet on/off, but preserve LAN connection


.DESCRIPTION


    Requires local admin rights.

    

    If a route to 0.0.0.0/0 exists remove it. If it does not exist

    add it to the primary (or specified) interface with the assumed

    (or specified) gateway address as the NextHop.


.EXAMPLE


    InternetToggle.ps1 -DefaultGateway 10.0.0.1 -InterfaceIndex 19


.NOTES


   Author : "Andrew Schott"<andrew@joletec.com>

   version: 1.0

   Date   : 2021-06-10


#>




param(

    $DefualtGateway = "10.0.0.1",

    $InterfaceIndex = (Get-NetIPConfiguration).NetProfile.InterfaceIndex

)



TRY{

    Get-NetRoute -DestinationPrefix "0.0.0.0/0" -ErrorAction Stop

}CATCH{

    New-NetRoute -DestinationPrefix "0.0.0.0/0" -InterfaceIndex $InterfaceIndex -NextHop $DefualtGateway

    $RouteExisted = $false

}


IF($RouteExisted -eq $null){

    Remove-NetRoute -DestinationPrefix "0.0.0.0/0" -Confirm:$false

}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article