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?

June 24th, 2015 6:02pm

Use the client name and not the IP.

Your issue is not a scripting issue.  You should post in the networking forum fro assistance with setting up and using  A VPN.  RoboCopy is not a script it is a utility.

Free Windows Admin Tool Kit Click here and download it now
June 24th, 2015 6:55pm

Use the client name and not the IP.

Your issue is not a scripting issue.  You should post in the networking forum fro assistance with setting up and using  A VPN.  RoboCopy is not a script it is a utility.

June 25th, 2015 3:10pm

What is the question.  We can answer questions but we cannot do a laundry list.

If you are having issues with you VPN client then contact the vendor of the clients software.

In Windows we locate things by name not by IP as the IP is usually dynamic.  YOu cannot discover a VPN client fromt eh network in any reasonable way as the client always appears to be on the local network.  What is the name of the client?

Free Windows Admin Tool Kit Click here and download it now
June 25th, 2015 5:07pm

What is the question.  We can answer questions but we cannot do a laundry list.

If you are having issues with you VPN client then contact the vendor of the clients software.

In Windows we locate things by name not by IP as the IP is usually dynamic.  YOu cannot discover a VPN client fromt eh network in any reasonable way as the client always appears to be on the local network.  What is the name of the client?

June 25th, 2015 5:30pm

Why not just write in in PowerShell?  Why do you do it in pseudo code?

I will note that this will not likely work from the client as you are likely routed through a DMZ and the IP on you end is not visible on the remote end.

If you are just asking how to test a path then use Test-Path

help test-path -full

read the examples and instructions.

Free Windows Admin Tool Kit Click here and download it now
June 25th, 2015 5:42pm

Why not just write in in PowerShell?  Why do you do it in pseudo code?

I think you might not understand english and that is the problem here.

 I do not know Powershell so I am asking how do I write that pseudo code in Powershell...

June 25th, 2015 5:47pm

I understand. You want someone to write a script for you;  correct?

Free Windows Admin Tool Kit Click here and download it now
June 25th, 2015 5:52pm

I understand. You want someone to write a script for you;  correct?

June 26th, 2015 12:44am

For custom scripts you can post here: https://gallery.technet.microsoft.com/scriptcenter/site/requests

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 5:20am

For custom scripts you can post here: https://gallery.technet.microsoft.com/scriptcenter/site/requests

June 26th, 2015 11:44am

Bottom of the page and you need to be logged in.

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 12:33pm

here' something I wrote for work. maybe you could modify it

$smtp = "192.168.100.100"
$from = "email@address.com"
$to   = "email@address.com"
$attach = "c:\temp\email35.zip"
$to   = "email@address.com","email2@address.com"

$copyto   = "\\serverto\shareto" 
$copyfrom = "\\serverfrom\sharefrom"

Remove-Item $attach -Force
Get-ChildItem -path $copyfrom|where-object {$_.mode -match "d"} | ForEach-Object -Process {
#write-host "`r`n`r`nname: $($_.name)`r`n"
if ( (-not (test-path "c:\temp\robocopy.$($_.name).txt")) -and (-not ($_.Name -eq "1_")) -and (-not ($_.Name -eq "1")) -and (-not ($_.Name -eq "12")) -and ($_.Name -like "??_????")) {
write-host "get-date: $(get-date)`r`nLastWritten: $($_.LastWriteTime)`r`nc:\temp\robocopy.$($_.name).txt" 
invoke-expression $("robocopy $(Join-Path -path $($copyfrom) -childpath $_.name) $(Join-Path -path $($copyto) -childpath $_.name) /COPY:DT /E /V /NS /NDL /NFL /xo /NP /R:3 /W:5 /LOG:c:\temp\logs\robocopy.$($_.name).txt")
}  #log file check
}  #dir list

gci "c:\temp\logs\robocopy.*.txt"|% { $eBody += "$($_.FullName)<BR><BR>$(get-content $_.Fullname|select-object -last 12|Out-String)<BR><BR>"}
start-process "C:\7za.exe"  "a $attach c:\temp\logs\robocopy.*.txt" -windowstyle Minimized -wait
send-mailmessage -SmtpServer $smtp -From $from -To $to -Subject "File Sync Log $(get-date -Format "d")" `
                             -Body "The attached log files created by the file sync process regarding files copied to DataCenter`r`n`r`n<span style='font-size:12.0pt;font-family:`"Lucida Console`"'><pre>$ebody</pre></span>" `
                             -BodyAsHtml `
                             -Attachments $attach




  • Edited by MegaRAM 13 hours 24 minutes ago
June 26th, 2015 1:43pm

here' something I wrote for work. maybe you could modify it

$smtp = "192.168.100.100"
$from = "email@address.com"
$to   = "email@address.com"
$attach = "c:\temp\email35.zip"
$to   = "email@address.com","email2@address.com"

$copyto   = "\\serverto\shareto" 
$copyfrom = "\\serverfrom\sharefrom"

Remove-Item $attach -Force
Get-ChildItem -path $copyfrom|where-object {$_.mode -match "d"} | ForEach-Object -Process {
#write-host "`r`n`r`nname: $($_.name)`r`n"
if ( (-not (test-path "c:\temp\robocopy.$($_.name).txt")) -and (-not ($_.Name -eq "1_")) -and (-not ($_.Name -eq "1")) -and (-not ($_.Name -eq "12")) -and ($_.Name -like "??_????")) {
write-host "get-date: $(get-date)`r`nLastWritten: $($_.LastWriteTime)`r`nc:\temp\robocopy.$($_.name).txt" 
invoke-expression $("robocopy $(Join-Path -path $($copyfrom) -childpath $_.name) $(Join-Path -path $($copyto) -childpath $_.name) /COPY:DT /E /V /NS /NDL /NFL /xo /NP /R:3 /W:5 /LOG:c:\temp\logs\robocopy.$($_.name).txt")
}  #log file check
}  #dir list

gci "c:\temp\logs\robocopy.*.txt"|% { $eBody += "$($_.FullName)<BR><BR>$(get-content $_.Fullname|select-object -last 12|Out-String)<BR><BR>"}
start-process "C:\7za.exe"  "a $attach c:\temp\logs\robocopy.*.txt" -windowstyle Minimized -wait
send-mailmessage -SmtpServer $smtp -From $from -To $to -Subject "File Sync Log $(get-date -Format "d")" `
                             -Body "The attached log files created by the file sync process regarding files copied to DataCenter`r`n`r`n<span style='font-size:12.0pt;font-family:`"Lucida Console`"'><pre>$ebody</pre></span>" `
                             -BodyAsHtml `
                             -Attachments $attach




  • Edited by MegaRAM 13 hours 18 minutes ago
Free Windows Admin Tool Kit Click here and download it now
June 26th, 2015 1:45pm

here' something I wrote for work. maybe you could modify it

$smtp = "192.168.100.100"
$from = "email@address.com"
$to   = "email@address.com"
$attach = "c:\temp\email35.zip"
$to   = "email@address.com","email2@address.com"

$copyto   = "\\serverto\shareto" 
$copyfrom = "\\serverfrom\sharefrom"

Remove-Item $attach -Force
Get-ChildItem -path $copyfrom|where-object {$_.mode -match "d"} | ForEach-Object -Process {
#write-host "`r`n`r`nname: $($_.name)`r`n"
if ( (-not (test-path "c:\temp\robocopy.$($_.name).txt")) -and (-not ($_.Name -eq "1_")) -and (-not ($_.Name -eq "1")) -and (-not ($_.Name -eq "12")) -and ($_.Name -like "??_????")) {
write-host "get-date: $(get-date)`r`nLastWritten: $($_.LastWriteTime)`r`nc:\temp\robocopy.$($_.name).txt" 
invoke-expression $("robocopy $(Join-Path -path $($copyfrom) -childpath $_.name) $(Join-Path -path $($copyto) -childpath $_.name) /COPY:DT /E /V /NS /NDL /NFL /xo /NP /R:3 /W:5 /LOG:c:\temp\logs\robocopy.$($_.name).txt")
}  #log file check
}  #dir list

gci "c:\temp\logs\robocopy.*.txt"|% { $eBody += "$($_.FullName)<BR><BR>$(get-content $_.Fullname|select-object -last 12|Out-String)<BR><BR>"}
start-process "C:\7za.exe"  "a $attach c:\temp\logs\robocopy.*.txt" -windowstyle Minimized -wait
send-mailmessage -SmtpServer $smtp -From $from -To $to -Subject "File Sync Log $(get-date -Format "d")" `
                             -Body "The attached log files created by the file sync process regarding files copied to DataCenter`r`n`r`n<span style='font-size:12.0pt;font-family:`"Lucida Console`"'><pre>$ebody</pre></span>" `
                             -BodyAsHtml `
                             -Attachments $attach




  • Edited by MegaRAM Friday, June 26, 2015 5:44 PM
June 26th, 2015 5:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics