Wait for scheduled task

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 :wink:
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!

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}

Yep. You’re missing that extra set of parens…

Thanks!