$ServerName = "192.168.40.1" ##### Script Starts Here ###### foreach ($Server in $ServerName) { if (test-Connection -ComputerName $Server -Count 2 -Quiet ) { write-Host "$Server is alive and Pinging " -ForegroundColor Green } else { Write-Host "$Server is down." Write-Host "Disconnecting..." rasdial.exe "Woodside" /DISCONNECT Write-Host "Connecting..." rasdial.exe "Woodside" user vpnpassword } }