Author Posts

November 5, 2014 at 12:48 pm

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!

November 6, 2014 at 8:58 am

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}

November 6, 2014 at 9:11 am

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