windows下自动连接openvpn的powershell脚本

windows下的openvpn自动连接powershell脚本,自动尝试指定目录下的所有.ovpn文件 powershell的脚本如下所示: $ovpn_dir = "D:\MyProject\mybat\vpnconf" $auth_file = "D:\MyProject\mybat\auth.txt" $log_file = "D:\MyProject\mybat\temp.log" foreach ($ovpn_file in Get-ChildItem -Path $ovpn_dir -Filter *.ovpn) { Write-Host "Trying $($ovpn_file.Name)" Remove-Item $log_file -ErrorAction SilentlyContinue $process = Start-Process -FilePath "C:\Program Files\OpenVPN\bin\openvpn.exe" -ArgumentList "--config $ovpn_file --auth-user-pass $auth_file" -NoNewWindow -PassThru -RedirectStandardOutput $log_file $connected = $false while (!$process.HasExited) { $content = Get-Content $log_file if ($content -match "Initialization Sequence Completed") { $connected = $true Write-Host "Connected successfully!" break } Start-Sleep -Milliseconds 1000 } if ($connected) { $inputStr = Read-Host "Type 'stop' to terminate the program" if ($inputStr....

March 28, 2023 · 1 min · 137 words · Link