I want to return the Scheduled Tasks on a group of servers with all of the pertenant information into the K1000 as a Custom Inventory Rule so that I can report on which scheduled task runs on what machines and when. Or, if there is a better way to accomplish this, i'm all ears...

Answer Summary:
I would take a look at SCHTASKS /query from the command prompt. You should be able to tweak the command line for the info you want to return. After you get your command line sorted out you should be able to run something like this in a custom inventory rule. ShellCommandTextReturn(cmd.exe /c schtasks /query /V /FO LIST)
Cancel
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Answers

3

I would take a look at SCHTASKS /query from the command prompt. You should be able to tweak the command line for the info you want to return.

After you get your command line sorted out you should be able to run something like this in a custom inventory rule.

ShellCommandTextReturn(cmd.exe schtasks /query)
Answered 09/03/2013 by: dugullett
Red Belt

  • Here is what I've chosen as my command:
    "ShellCommandTextReturn(cmd.exe schtasks /query /V /FO LIST)"

    My problem now is that my machines won't update...I choose force check-in and they don't...
    • I'm thinking they are working on checking in, but that command line returns a lot of data. You might want to try taking out the /V. Is Kinventory.exe running when you pull up task manager on one of the machines?
      • It is not running. As soon as I disable the rule, the machines start checking in again. Some that have no scheduled tasks come back blank, but those that do never check in. I let them wait it out too and still no go.
      • What agent version are you running?
      • 5.5.25198
      • Would it be any faster if I ran the command as a script that outputs to text, and then return that text file to the KACE CIF?
      • I've had issues with "ShellCommandTextReturn" custom inventory with the 5.5 agents. I've been testing in my test lab and rules that worked in 5.4 no longer work in 5.5.

        Do you have any machines still with the 5.4 agent? If not try downgrading the agent. It's working for me. I did add the /c after cmd.exe.

        ShellCommandTextReturn(cmd.exe /c schtasks /query /FO LIST)
      • You could export it to text, but that will still require a "commandtextreturn" command. Which I haven't had luck with in 5.5. I haven't had a lot of time lately to see why.
      • Any thoughts as to how I could trim the information? There are some scheduled tasks that are not actually a recurring task, and I don't need those... It's listed as "Next Run Time: Never"
      • You can try a custom inventory That will return the info. I just found this script online, and it worked on my machine. I have not tested in a custom inventory rule though. If anything you can export the results to a .txt file and have Kace read it.

        http://www.fixitscripts.com/problems/getting-a-list-of-scheduled-tasks

        $schedule = new-object -com("Schedule.Service")
        $schedule.connect()
        $tasks = $schedule.getfolder("\").gettasks(0)
        $tasks | Format-Table Name , LastRunTime, NextRunTime # -AutoSize
        IF($tasks.count -eq 0) {Write-Host “Schedule is Emptyâ€}
        Read-Host


        Should work?

        ShellCommandTextReturn(powershell $schedule = new-object -com("Schedule.Service")
        $schedule.connect()
        $tasks = $schedule.getfolder("\").gettasks(0)
        $tasks | Format-Table Name , LastRunTime, NextRunTime # -AutoSize
        IF($tasks.count -eq 0) {Write-Host “Schedule is Emptyâ€}
        Read-Host)
  • adding the /c fixes the issue. still on 5.5... even with adding the /V
Please log in to comment
Answer this question or Comment on this question for clarity