 |
The toolkit configuration is as follows:
<sampler name="Scheduled Tasks"> <sampleInterval> <data>600</data> </sampleInterval> <var-hideColumns> <data> <column> <data>Power Management</data> </column> <column> <data>Delete Task If Not Rescheduled</data> </column> <column> <data>Repeat: Until: Time</data> </column> <column> <data>Repeat: Until: Duration</data> </column> <column> <data>Repeat: Stop If Still Running</data> </column> <column> <data>Repeat: Every</data> </column> <column> <data>Schedule</data> </column> </data> </var-hideColumns> <plugin> <toolkit> <samplerScript> <data>c:\Windows\System32\cscript.exe /nologo taskscript.vbs</data> </samplerScript> <script> <contents> <data>function extractFieldValue(line) s = split(line,":",2) str = Replace(s(1), ",", ";") extractFieldValue = trim(str) end function
function extractFieldName(line) s = split(line,":",2) str = Replace(s(0), ",", ";") extractFieldName = trim(str) end function
jobfilter = "Task"
'***** Run the command
Set WshShell = WScript.CreateObject("WScript.Shell") Set oExec = WshShell.Exec("c:\windows\system32\schtasks.exe /query /fo list /v")
newline = "" header = "" first = 1
'***** Process the output Do While oExec.StdOut.AtEndOfStream <> True
sline=oExec.StdOut.ReadLine
if sline = "" then '****This is the line break if newline <> "" then
if first = 1 and header <> "" then '**** Print column headers
header = left(header,len(header)-1) wscript.echo header header = "" first = 0 end if
'***Remove last comma newline = left(newline,len(newline)-1)
if(InStr(newline,jobfilter) > 0) then wscript.echo newline end if
newline = ""
end if
elseif (InStr(1, sline,"Folder:") > 0) or (InStr(1, sline,"INFO:") > 0) then
'wscript.echo "folder"
elseif (InStr(1, sline, ": ") > 0) then
newline = newline & extractFieldValue(sline) & ","
if first = 1 then header = header & extractFieldName(sline) & "," 'wscript.echo header end if
'wscript.echo extractFieldValue(sline)
end if Loop</data> </contents> <filename> <data>taskscript.vbs</data> </filename> </script> </toolkit> </plugin> <dataviews> <dataview name="Scheduled Tasks"> <firstColumn> <create> <columnName>Long Task Name</columnName> <combineColumns> <column>HostName</column> <literal> </literal> <column>TaskName</column> </combineColumns> </create> </firstColumn> </dataview> </dataviews> </sampler>
You will notice that there is a jobfilter = "Task" line in the script code. You can either remove / comment-out this line if you'd like to view all jobs or if needed, filter to a specific set task name. Removing this will display all scheduled tasks in the system.
(It's possible that the HTML may mess around with the XML formatting. If so, please see the attached file at the bottom of this article, labeled "Scheduled_Tasks.xml.txt" which has the correct XML file.)
|
Comments
0 comments
Please sign in to leave a comment.