Powershell script to find valid L2TP/IPSec VPN client and do robocopy transfer

Im using a L2TP/IPSec VPN mobile client and a ZyXEL ZyWALL USG50 as the server. I cannot find a way to set a static IP for a VPN mobile client so I cannot be guaranteed that it will be the same IP. In order to successfully transfer make the RoboCopy, I need to search for the VPN mobile client's IP I want to make the transfer to.

Obviously, a lot of time is wasted just searching for it but I really have no other choice.

On a "positive" note, Im sure there isnt going to be much VPN mobile clients so Im pretty sure it is always going to be 192.168.250.1 but at MOST it would be 192.168.250.10.

My idea for the script is:
1.Check if a IP is running (ping)
2.Check if a path on that IP actually exists. For example //192.168.250.1/PATH
3.Just to be sure this is the real location I want to transfer everything, check for a file such as "IAMTHECORRECTVPNBACKUPSERVER.txt"

4.Once those conditions are met (lets say for example purposes it is the IP of 192.168.250.7):

$IP="192.168.250.7& c:\windows\system32\Robocopy.exe "D:\folder" "\192.168.250.7\folder" /E /MT:20 /R:50 /W:10 /V /ETA /LOG:c:\robocopy$(Get-Date -format 'ddMMyyyyHHmmss')$IP.txt


5.Exit and finish the scheduled task


How could I do this in PowerShell?
Sign In or Register to comment.