Created
June 17, 2020 20:50
-
-
Save MartinCZ-byte/d24457a0fba35a3ec8b780f2b399f80a to your computer and use it in GitHub Desktop.
VPNprepare
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Test-Connection ## INTERNET ## | |
$TestNetDNS = Test-Connection -Count 1 www.google.com -ErrorAction SilentlyContinue | |
if ($TestNetDNS -ne $null) | |
{ | |
Write-Host "Internet available" -ForegroundColor Green | |
Stop-Process -Name "openvpn-gui" -Force 2> $null | |
Stop-Process -Name "openvpn" -Force 2> $null | |
##1 second waiting for OpenVpn renew## | |
Start-Sleep -Seconds 1 | |
C:\PROGRA~1\OpenVPN\bin\openvpn-gui.exe --connect test-user.ovpn | |
} | |
else | |
{ | |
Write-Host "Internet not available" -ForegroundColor Red | |
Write-Host "Try restart PC or check internet connection" -ForegroundColor Red | |
pause | |
exit | |
} | |
## Read-Host ## | |
function pause{ $null = Read-Host 'Please press enter after VPN connection started' } | |
pause | |
$VPN = Test-Connection -Delay 3 -Count 3 192.168.1.3 -ErrorAction SilentlyContinue | |
## VPN network confirmed ## RUN remote WOL script ## | |
if ($VPN -ne $null) | |
{ | |
Write-Host "VPN established" -ForegroundColor Green | |
##4 second waiting for exit## | |
Start-Sleep -Seconds 2 | |
exit | |
} | |
else | |
{ | |
Write-Host "VPN NOT OK" -ForegroundColor Red | |
Start-Sleep -Seconds 2 | |
exit | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment