While not connected to domain loop

Hey guys,

I’m new to powershell so forgive me if this is simple.

I’m writing a script for work and the first thing I need to do is run a loop that checks if our VPN is connected to the corporate intranet, and if not, open the VPN client and repeatedly check if you’ve logged in and connected, before moving on to opening other application.

I figured a while loop would be perfect but my problem is, how do I even check for connection to that specific intranet, as a condition of the loop? Seems to me like Test-Connection won’t work but maybe my syntax is just wrong or something….

Most recent example looks something like this:

while(Test-Connection -ComputerName ****.com $False){ Start-Process 'C:filepath-to-vpn-executable' } 

and this is the error I get.

Test-Connection : The RPC server is unavailable. (Exception from HRESULT: 0x800706BA) At line:1 char:7 + while(Test-Connection -ComputerName ****.com $False){ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [Test-Connection], COMException + FullyQualifiedErrorId : TestConnectionException,Microsoft.PowerShell.Commands.TestConnectionCommand 

I usually code in python, and I build scripts nearly every day, but these kinds of errors are feeling super foreign to me…

Maybe I’m just brain-fried from this long work week. Who knows. But any help would be EXTREMELY appreciated.

p.s. the **** is obviously replaced by the actual domain name in my script

submitted by /u/AutomaticManager888
[link] [comments]

Leave a Reply