[英]Duration of tasks with Windows Task scheduler
Is it possible to know the duration of a certain task to calculate from "Created Task Process" to "Task completed"?是否可以知道从“创建的任务流程”到“任务完成”计算某个任务的持续时间? Task scheduler only show the Last Run Time but not the duration of all execution.
任务调度程序只显示上次运行时间而不显示所有执行的持续时间。
You can do something like the following:您可以执行以下操作:
$TaskName = '\Task Name'
$StartTime = (Get-Date).Adddays(-7)
$EndTime = Get-Date
$filter = @{ LogName = 'Microsoft-Windows-TaskScheduler/Operational'
ID = 129,102
StartTime = $StartTime
EndTime = $EndTime
Data = $TaskName
}
Get-WinEvent -FilterHashTable $filter | Select-Object TimeCreated,@{n='Action';e={$_.TaskDisplayName}}
Explanation:解释:
For $TaskName
, you must enter the task name exactly as it would show in (Get-WinEvent).Properties
.对于
$TaskName
,您必须输入与(Get-WinEvent).Properties
显示的完全相同的任务名称。 You can also see this exact name in the task history messages.您还可以在任务历史消息中看到这个确切的名称。 It will likely contain the backslash in the name.
它可能会在名称中包含反斜杠。
You can set $StartTime
and $EndTime
to whatever you like here.您可以在此处将
$StartTime
和$EndTime
为您喜欢的任何值。 Having a time interval speeds up the query retrieval time.具有时间间隔可加快查询检索时间。
$filter
is where the magic happens. $filter
是神奇发生的地方。 It will ultimately be pushed into the parameter -FilterHashTable
.它最终会被推送到参数
-FilterHashTable
。 Since the ID
key can accept an array of [int]
, we can just comma separate the values.由于
ID
键可以接受[int]
数组,我们可以用逗号分隔值。 129
is Created Task Process
. 129
是Created Task Process
。 102
is Task Completed
. 102
是Task Completed
。 Data
does not accept wildcards so we must be exact with the task name as it would show in a System.Diagnostics.Eventing.Reader.EventProperty
property. Data
不接受通配符,因此我们必须准确使用任务名称,因为它会显示在System.Diagnostics.Eventing.Reader.EventProperty
属性中。 If you do not use Data
, you will have to rely on Where-Object
to further filter your task data by the task name, which will be significantly slower.如果您不使用
Data
,您将不得不依靠Where-Object
按任务名称进一步过滤您的任务数据,这将显着变慢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.