keep checking if a program is running.

Comments

2 comments

  • Stephen Valdinger
    Do {

        Out-Null

    }

    While (!(Get-Process | Where {$_.Name -like "epicor*"}))

    Get-Process | Where { $_.Name -like "epicor*"} | Stop-Process

      That should get you where you want to go. It'll run on the workstation until the process is running, then kill it and exit the script. If you need it to just keep looping and never terminate, then we need to make some adjustments, but this should do the trick. 

    0
    Comment actions Permalink
  • Colby Bouma

    Recursion is typically when a function calls itself. Loops are not recursion.

    On my computer the output of Get-Process was never $False. I recommend checking for $null instead.

    Here's an untested script I threw together that I think should work.

    function Stop-Epicor {

    $Epicor_Process = Get-Process Epicor -ErrorAction SilentlyContinue

    if ( $Epicor_Process -eq $null ) {

    Start-Sleep -Seconds 15
    Stop-Epicor

    } else {

    Stop-Process -Force $Epicor_Process

    }

    }

    Stop-Epicor
    0
    Comment actions Permalink

Please sign in to leave a comment.