我正在编写一个PowerShell脚本,它将计算来自的记录数
请求具有上一个$interval
中发生的特定ID的日志
秒。在当前版本的脚本中,我正在打印$log
返回的事件以及RecordCount
。但是,RecordCount
是
不打印。
我的脚本的当前版本是:
$log_name = 'Application'
$event_id = 1003
$interval = (get-date).AddSeconds(-7200) # Last 2 hours.
$count = 0
$log = Get-WinEvent -EA silentlycontinue `
-FilterHashTable @{ LogName=$log_name;
StartTime=$interval;
id=$event_id }
$log
$log.RecordCount
输出结果为:
PS C:\temp> .\log_monitor
TimeCreated ProviderName Id Message
----------- ------------ -- -------
01/25/2016 12:34:40 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:34:40 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:34:39 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:34:39 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:14:22 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:14:22 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:14:22 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:14:22 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:05:41 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:05:41 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:05:41 PM Office Software Protection... 1003 The Software Protection se...
01/25/2016 12:05:41 PM Office Software Protection... 1003 The Software Protection se...
PS C:\temp>
请注意,RecordCount
未打印。
答案 0 :(得分:1)
相反,只需使用Count
属性,如
$log.Count