Start New Discussion within our Software Development Community

I have a mobile VPN client that I want to backup to. The problem is that it does not have a static IP to due it being L2TP/IPSec. Thats the bad news. The good news is that there wont be too many VPN clients (at most 10 if that) so Ill be to search for it easy.

Basically, I should go thru a list of IPs from 192.168.250.0 to 192.168.250.10 and check if the IP is up and running (ping). Once I check it is up and running, I should check for a path //192.168.250.1/PATH and just to be 100% sure its the correct place, Ill serach for a single text file with a single name such as "IAMTHECORRECTVPNBACKUPSERVER.txt" once that is done, I start a robocopy there....

I have the robocopy implemented in PowerShell now I need to implement the pinging and searching the correct IP. How could I do this?

First 192.168.250.0 is a reserved adress to designate a subnetwork, a host can't have the last octet equal to 0 .
That said, if you want to scan from 192.168.250.1 to 192.168.250.11 you can do

(1..11)|foreach{
    if( test-connexion -quiet 192.168.250.$_ -eq $true){ #ping test
        if( test-path \\192.168.250.$_\path\IAMTHECORRECTVPNBACKUPSERVER.txt -eq $true ){
            #do robocopy
        }
        else{
            write-host "host 192.168.250.$_ is not the backupserver"
        }
    }
    else{
        write-host "host 192.168.250.$_  is offline"
    }
}
This article has been dead for over six months. Start a new discussion instead.