Wait for scheduled task

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of bvi1998 . bvi1998 . 2 years, 1 month ago.

  • Author
    Posts
  • #20366
    Profile photo of bvi1998 .
    bvi1998 .
    Participant

    Hi,
    I've been banging my head trying to figure out the following:
    I have a scheduled task with two actions. When the first is done, I want the second to start, but I don't want to wait forever 😉
    I thought I could possibly do a while testing on two tests, but I can't make it work.
    This is my attempt:

    $i = 0
    While((schtasks.exe /query /TN "$Taskname" /FO CSV | ConvertFrom-Csv | select -expandproperty Status -first 1) -eq "Running") -and ($i -ne 6)
    {$i = $i++
    sleep -s 5}

    Basically I want to check to see if the job is still running, but not wait forever for it. After the timeout, I will check if a service is running in the rest of my script.

    Thanks for any help!

  • #20405
    Profile photo of Tim Pringle
    Tim Pringle
    Participant

    I think you"ll need to wrap it in another set of brackets for it to validate the whole condition

    $i = 0
    While(((schtasks.exe /query /TN "$Taskname" /FO CSV | ConvertFrom-Csv | select -expandproperty Status -first 1) -eq "Running") -and ($i -ne 6))
    {$i = $i++
    sleep -s 5}
    
  • #20407
    Profile photo of Charles Downing
    Charles Downing
    Participant

    Yep. You're missing that extra set of parens...

  • #20413
    Profile photo of bvi1998 .
    bvi1998 .
    Participant

    Thanks!

You must be logged in to reply to this topic.