Forum Discussion

ksrover's avatar
ksrover
Icon for Altostratus rankAltostratus
Mar 17, 2023
Solved

F5 VPN command-line and Windows task scheduler

We have a vendor that requires a connection to their F5 VPN before accessing data.  I have a powershell script to command-line this connection successfully, but when I attempt to run this same script in Windows (2016) Task Scheduler, the VPN connection doesn't look to even be attempted.  I've attempted this while logged in (admin), made sure the execution policy is set to bypass, and have tried using 'Run with highest priviledges' (in TS).

The PS script that I'm using is :

 

 

## Start VPN connection
cd "C:\Program Files (x86)\F5 VPN"
.\f5fpc -start /u "myusername" /p "mypassword" /q

## Wait 10s to complete connection
Start-Sleep -Seconds 10

## Get VPN connectionID
$e = (.\f5fpc -info | findstr /r ^[1-9] | ForEach-Object {$_.Substring(0,7)})

## FTP commands
## This is where I would run our SFTP commands

## Kill connection
.\f5fpc -stop /s $e

 

 

The TS action is Start a Program = "powershell" with Arguments = "-ExecutionPolicy ByPass C:\scheduled_jobs\F5VPN_connection.ps1"

What could I be missing to why this won't connect when executed in Task Scheduler?  Or is there another way to make this connection on a unattended schedule?

Thank you

  • After some more testing:

    As a regular user with RDP rights (only), executing the PS script itself runs perfectly - connect to F5 VPN, run SFTP commands, move files, disconnect VPN connection.  However, when running this same script in Task Scheduler (as the regular user), the F5 connection is made, but it not usable by any other client (FTP client, browser, etc).  

    I had to change the user the scheduled task was being executed as from the regular user, to a user with administrator rights on the server.  After that, the PS script, run in task scheduler, runs as intended.

2 Replies

  • After some more testing:

    As a regular user with RDP rights (only), executing the PS script itself runs perfectly - connect to F5 VPN, run SFTP commands, move files, disconnect VPN connection.  However, when running this same script in Task Scheduler (as the regular user), the F5 connection is made, but it not usable by any other client (FTP client, browser, etc).  

    I had to change the user the scheduled task was being executed as from the regular user, to a user with administrator rights on the server.  After that, the PS script, run in task scheduler, runs as intended.

  • Well, I put in a transcript output for the PS script and removed the SFTP commands.  After testing and looking at the transcript, the VPN connection is being made after all.  I'm not sure what I did differently, but it's apparent that the VPN command-line connection is not the issue.