Powershell 一个视图中的多天、自定义筛选、多个日志事件
如何在一台服务器上获取周一至周五下午5:00至10:00之间的活动 这将为特定日期的时间跨度提供事件 获取事件日志-日志名系统| 其中对象{$\.timewrited-ge2/5/14000:00-和$\.timewrited-le2/7/14000:00} 然后,我如何将多个日志中的自定义筛选事件同时排序到一个视图中。此方法不适用于“get wineventlog” $time=[System.Management.ManagementDateTimeConverter]::ToDmtfDateTimeGet-Date.AddHours-12 $sys=Get WmiObject-Class win32\u ntlogevent-filter logfile='System'和Sourcename='Srv'和TimeGenerated>='$time';选择-First 10 $app=Get WmiObject-Class win32\u ntlogevent-filter logfile='Application'和eventType<'3'和TimeGenerated>='$time';选择-前10个Powershell 一个视图中的多天、自定义筛选、多个日志事件,powershell,powershell-2.0,event-log,remote-server,Powershell,Powershell 2.0,Event Log,Remote Server,如何在一台服务器上获取周一至周五下午5:00至10:00之间的活动 这将为特定日期的时间跨度提供事件 获取事件日志-日志名系统| 其中对象{$\.timewrited-ge2/5/14000:00-和$\.timewrited-le2/7/14000:00} 然后,我如何将多个日志中的自定义筛选事件同时排序到一个视图中。此方法不适用于“get wineventlog” $time=[System.Management.ManagementDateTimeConverter]::ToDmtfDat
$$sys+$app |排序时间写入-降序|选择-属性日志文件、事件代码、源名称、消息| ft-自动调整大小如果我读对了这篇文章,您需要在周一到周五每晚5点到10点之间对日志进行梳理。为此,我会像您开始做的那样使用Get EventLog。该脚本将从指定的开始日期开始迭代5天,并按照过滤器的描述从每天下午5点到晚上10点提取日志。它还向每个项添加一个LogFile元素,以说明它是否来自系统或应用程序日志
$StartDate = Get-Date "2/5/14"
$TargetComputer = "BP1XEUTS399"
$Logs = @()
For($i=0;$i -lt 5;$i++){
$TargetDate = $StartDate.AddDays($i)
$From = $TargetDate.AddHours(17)
$To = $From.AddHours(5)
#Remember what Error Actions is currently set to, and then set it to silent to avoid errors thrown when no log entries are found due to filters
$CurErrAct = $ErrorActionPreference
$ErrorActionPreference = "SilentlyContinue"
$Sys = Get-EventLog -Log System -After $From -Before $To -Source "Srv"
$Sys|%{$_|Add-Member -MemberType NoteProperty -Name "LogFile" -Value "System"}
$Apps = Get-EventLog -Log Application -ComputerName $TargetComputer -After $From -Before $To -EntryType Error,Warning
$Apps|%{$_|Add-Member -MemberType NoteProperty -Name "LogFile" -Value "Applications"}
$Logs += $Sys
$Logs += $Apps
#Set Error Actions back to what it was.
$ErrorActionPreference = $CurErrAct
}
$Logs|FT -autosize LogFile,EntryType,Source,Message
注意,我尽可能地复制了您在问题中的内容,因此所提取的系统日志是本地系统日志。应用程序日志位于远程计算机上。如果要在同一台计算机上提取系统日志,请将-ComputerName$TargetComputer添加到$Sys=Get EventLog行中。foreach$i in$5..7{$c=@$a=Get EventLog-LogName system-在$i 2014年1月16:30之后-在$i 2014年1月20:00之前-Source SRV$c+=$a$b=Get EventLog-LogName应用程序-在$i 2014年1月16:30之后-在$i 2014年1月20:00之前-EntryType错误|?{$\源代码-不匹配“框架”}$c+=$b$c |排序时间写入-降序|英尺-自动调整入口类型、时间写入、源、消息}谢谢..我永远无法在评论中获得正确的格式。。。。