Script to start and stop Microsoft Direct Access when needed

Script to start and stop Microsoft Direct Access when needed

Why?

With COVID-19 (Corona) the need to work from home/ remote is needed more then ever. We were lucky to have a decent setup in the company I work for to support over 350 users to work remote without any major issues.

Besides our trusty clustered VPN solution we have Direct Access (DA) running for our users. Some users need to connect to certain customers their VPNs and it seems that these don’t play nicely with DA.

So after some searching on how you can disable DA safely and keep it turned off when you would for example disconnect your network or other VPN I’ve created the below script.

How?

Start-Service NcaSvc
Start-Service iphlpsvc
Start-Service NcaSvc

Code

################################
#                              #
# Start-Stop and get status DA #
#                              #
# V1.0 - Laurens Gregoir       #
#                              #
################################

function stop-DA
{
    Stop-Service iphlpsvc -Force
}

function start-DA
{
    Start-Service NcaSvc
    Start-Service iphlpsvc
    Start-Service NcaSvc
}

# menu options
function Show-Menu
{
    $service = Get-Service iphlpsvc
    $service.Refresh()


    if ($service.Status -eq 'Running')
    {
        $status = "DA is Running"
    }

    elseif($service.Status -eq 'Stopped')
    {
        $status = "DA is NOT Running"
    }

     param
     (
           [string]$Title = 'DA servicer'
     )

     cls

     Write-Host "================ $Title ================"

     Write-Host "DA Service status = $Status"
     
     

     Write-Host "1: Press '1' to STOP Direct Access"
     Write-Host "2: Press '2' to START Direct Access."
     Write-Host ""
     Write-Host "Q: Press 'Q' to quit."
     Write-Host ""
}

# Options
do
{
     Show-Menu
     
     $input = Read-Host "Please make a selection"
     
     switch ($input)
     {

        '1' { stop-DA }
        
        '2' { start-DA }
        
        'q'
        {
            cls
            "Bye"

            return
        }
     }
     pause
}
until ($input -eq 'q')

Gallery

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *