Wait for scheduled task

Welcome Forums General PowerShell Q&A Wait for scheduled task

This topic contains 3 replies, has 3 voices, and was last updated by

 
Participant
4 years, 2 months ago.

  • Author
    Posts
  • #20366

    Participant
    Points: 31
    Rank: Member

    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

    Participant
    Points: 60
    Rank: Member

    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

    Participant
    Points: 44
    Rank: Member

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

  • #20413

    Participant
    Points: 31
    Rank: Member

    Thanks!

The topic ‘Wait for scheduled task’ is closed to new replies.