Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PowerShell获取taskscheduler历史记录级别_Powershell_History_Taskscheduler - Fatal编程技术网

使用PowerShell获取taskscheduler历史记录级别

使用PowerShell获取taskscheduler历史记录级别,powershell,history,taskscheduler,Powershell,History,Taskscheduler,如何使用PowerShell获取taskscheduler的历史级别 使用: $EventFilter = @{ LogName = 'Microsoft-Windows-TaskScheduler/Operational' Id = 100 StartTime = [datetime]::Now.AddDays(-1) } # PropertySelector for the Correlation id (the InstanceId) and task name [

如何使用PowerShell获取taskscheduler的历史级别

使用:

$EventFilter = @{
    LogName = 'Microsoft-Windows-TaskScheduler/Operational'
    Id = 100
    StartTime = [datetime]::Now.AddDays(-1)
}
# PropertySelector for the Correlation id (the InstanceId) and task name
[string[]]$PropertyQueries = @(
    'Event/EventData/Data[@Name="InstanceId"]'
    'Event/EventData/Data[@Name="TaskName"]'
)
$PropertySelector = New-Object System.Diagnostics.Eventing.Reader.EventLogPropertySelector @(,$PropertyQueries)

# Loop through the start events
$TaskInvocations = foreach($StartEvent in Get-WinEvent -FilterHashtable $EventFilter){

    # Grab the InstanceId and Task Name from the start event
    $InstanceId,$TaskName = $StartEvent.GetPropertyValues($PropertySelector)

    # Create custom object with the name and start event, query end event by InstanceId
    [pscustomobject]@{
        TaskName = $TaskName
        StartTime = $StartEvent.TimeCreated
        EndTime = $(Get-WinEvent -FilterXPath "*[System[(EventID=102)] and EventData[Data[@Name=""InstanceId""] and Data=""{$InstanceId}""]]" -LogName 'Microsoft-Windows-TaskScheduler/Operational' -ErrorAction SilentlyContinue).TimeCreated
    }
}
$TaskInvocations

参考链接:

mate,你试过什么?您可以使用
$service=newobject-ComObject(“Schedule.service”)$service.Connect()$rootFolder=$service.GetFolder(“\”)正在工作,先生。。。。您还可以帮助我从任务历史记录中获取任务的事件ID吗?@bhargavporapu:您需要自己尝试所有这些。因此,这不是一个脚本交付服务,它更多的是一个帮助论坛,ppl在这里陷入困境并尝试找出方向。我看不到你们方面的任何努力。我只是想知道,如果我们提供了一个特定任务的名称,我想得到它,并将事件Id作为一个硬编码值。好的,没什么好担心的,我得到了解决方案,谢谢你的帮助。很乐意帮助。享受编码:)@bhargavporapu