start-process then wait until ping returns true

This topic contains 3 replies, has 3 voices, and was last updated by  Martin Thomsen 1 year, 8 months ago.

  • Author
  • #53839

    Martin Thomsen


    I need something that will start a process then wait until ping is true

    $ 'C:\tmp\myVPN.exe'

    do {$ping=test-connection -computer "myserver.domain.local" -quiet} until($ping)

    #then do more stuff after above ping returns true.

    but it halts after starting the software since the vpn doesn't shut down (obviously)

    how can I start the vpn in a seperate process? or whatever I need to do ?

  • #53843

    Daniel Krebs

    The Start-Process cmdlet will launch an executable in a separate process unless being told otherwise.

    Get-Help Start-Process -Online

  • #53845

    Richard Diphoorn

    Daniel is right. Use Start-Process here like this:

    $process = Start-Process -FilePath 'C:\tmp\myVPN.exe' -PassThru

    I'm putting the returned object in a variable, so that you can use it to do some checks on. Like this:

    $process | Get-Process
  • #53904

    Martin Thomsen

    Thx guys.. I actually did something else.. I added '-asJob' which seems to achieve the same thing.. but I will definetely change to the above..

You must be logged in to reply to this topic.