title: Check SCHTASKS Status in Batch File
body: <p>I have written a batch file with the following commands to check the schtasks status and I am planning to put this in a loop. </p>
  
  <pre><code>FOR /F %%I IN ('SCHTASKS /QUERY /S &lt;servername&gt; /FO LIST /TN "\MICROSOFT\deploy_db" ^| FIND /C "Running"') DO (IF %%I == 0 ( SET STATUS=Running) Else ( SET Status=Ready))
  ECHO %%I
  ECHO %STATUS%
  </code></pre>
  
  <p>But I am getting this following error:</p>
  
  <pre><code>ECHO is off.
  ECHO is off.
  </code></pre>
  
  <p>If I write the following:</p>
  
  <pre><code>FOR /F %%I IN ('SCHTASKS /QUERY /S &lt;servername&gt; /FO LIST /TN "\MICROSOFT\deploy_db" ^| FIND /C "Running"') DO 
  (IF %%I == 0 ( SET STATUS=Running) Else ( SET Status=Ready))
  ECHO %%I
  ECHO %STATUS%
  </code></pre>
  
  <p>If I do the above the get the following:</p>
  
  <pre><code>The syntax of the command is incorrect
  </code></pre>
  
  <p>If I write the following:</p>
  
  <pre><code>FOR /F %%I IN ('SCHTASKS /QUERY /S &lt;servername&gt; /FO LIST /TN "\MICROSOFT\deploy_db" ^| FIND /C "Running"') DO (IF %%I == 0 ( SET STATUS=Running) Else ( SET Status=Ready))
  ECHO %STATUS%
  </code></pre>
  
  <p>If I do the above the get the following:</p>
  
  <pre><code>Running
  </code></pre>
  
  <p>Can anyone please help me with the script.</p>