none
Scheduled Task Status check RRS feed

  • Question

  • Hi,

    Im trying to get Nagios to check Windows Scheduled Tasks by Status.

    Basically i want to know when tasks are Disabled or Could Not Start so i need to monitor the Status field.

    I found a script on the interweb that does what i need:


    @schtasks /query /fo csv | find "Could not start" | find "Disabled" /V
    @IF %ERRORLEVEL% EQU 1 goto NoFails1
    @echo Fail:2 Task failed to Start
    @EXIT 2
    
    :NoFails1
    @schtasks /query /fo csv | find "Could not start" 
    @IF %ERRORLEVEL% EQU 1 goto NoFails2
    @echo Fail:1 Task Failed but Disabled
    @EXIT 1
    
    :NoFails2
    @echo OK:0 
    @EXIT 0

    Now i just need to be able to modify slightly so that it excludes all system tasks and only include manual tasks.

    Snag....i have no idea how to do it! :)

    Anybody able to chuck in the relevant bit of code needed to exclude system tasks please?

    Batch file or powershell, i dont mind, its only in a batch file as thats what i found.

    THANKYOU!


    • Edited by Fulgent Thursday, February 27, 2014 5:23 PM
    Thursday, February 27, 2014 5:22 PM

Answers

  • My apologies Forest Brook if i broke any rules.
    -> You did not break any rules. You just need to be aware that in this forum you get help with scripting problems. If you need help with operating-system problems (e.g. Windows 7) then you get it in a Windows 7 forum. 

    Because it was the slight editing of the afore mentioned batch script i presumed it belonged in the scripting forum.
    -> You can edit script repository files in any way you like.

    I didnt think it would be correct to just post here and ask for somebody to write me a whole powershell script to check for a Disabled state scheduled task.
    -> Respondents in this forum will gladly help you with your own script. They do not normally write scripts on request, recommending instead that you hire a consultant. However, there are exceptions.

    If you can work out a rule that clearly distinguishes a System task from a user-generated task then someone will suggest a way to script it.

    Saturday, March 1, 2014 11:14 AM

All replies

  • Anybody able to chuck in the relevant bit of code needed to exclude system tasks please?

    Chucking in the relevant bit of code is easy but only after you have done your own homework. You must run this command

    schtasks /query /fo csv > tasks.txt

    then examine the output file and report how exactly system tasks distinguish themselves from other tasks.

    Thursday, February 27, 2014 6:35 PM
  • Hi Forest Brook,

    So having run that command you gave me it looks like all i need to do is exclude the \microsoft directory

    Is this correct?

    Looking at http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx

    Suggests i could use the /TN switch and specify the actual tasks name - but i dont think this will help me as i need this script to check multiple different tasks?

    Friday, February 28, 2014 9:44 AM
  • All i need to do is exclude the \microsoft directory

    Is this correct?

    Looking at http://msdn.microsoft.com/en-us/library/windows/desktop/bb736357%28v=vs.85%29.aspx

    Suggests i could use the /TN switch and specify the actual tasks name - but i dont think this will help me as i need this script to check multiple different tasks?

    In this scripting forum, respondents gladly assist posters with scripting problems, e.g. how to write some code in batch, VBScript or PowerShell. None of your questions relate to scripting. They all concern the correct use of schtask.exe which would be a topic for the particular version of Windows that you use.

    This command (which you could call a "script" if you're so inclinded) will filter out all Microsoft\Windows tasks:

    schtasks /query /fo csv | find /i /v "\Microsoft\Windows"

    You can add further filters, e.g. to suppress the header lines.


    Friday, February 28, 2014 4:51 PM
  • My apologies Forest Brook if i broke any rules.

    Because it was the slight editing of the afore mentioned batch script i presumed it belonged in the scripting forum.

    I didnt think it would be correct to just post here and ask for somebody to write me a whole powershell script to check for a Disabled state scheduled task.

    Saturday, March 1, 2014 10:18 AM
  • My apologies Forest Brook if i broke any rules.
    -> You did not break any rules. You just need to be aware that in this forum you get help with scripting problems. If you need help with operating-system problems (e.g. Windows 7) then you get it in a Windows 7 forum. 

    Because it was the slight editing of the afore mentioned batch script i presumed it belonged in the scripting forum.
    -> You can edit script repository files in any way you like.

    I didnt think it would be correct to just post here and ask for somebody to write me a whole powershell script to check for a Disabled state scheduled task.
    -> Respondents in this forum will gladly help you with your own script. They do not normally write scripts on request, recommending instead that you hire a consultant. However, there are exceptions.

    If you can work out a rule that clearly distinguishes a System task from a user-generated task then someone will suggest a way to script it.

    Saturday, March 1, 2014 11:14 AM