Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MartinCZ-byte/d24457a0fba35a3ec8b780f2b399f80a to your computer and use it in GitHub Desktop.
Save MartinCZ-byte/d24457a0fba35a3ec8b780f2b399f80a to your computer and use it in GitHub Desktop.
VPNprepare
## 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