在交互模式下,这是有效的:
Get-Eventlog -log application -after ((get-date).addMinutes(-360)) -EntryType Error现在我想要过滤掉某些消息,下面的消息没有过滤所需的单词:
Get-Eventlog -log application -after ((get-date).addMinutes(-360)) -EntryType Error | where-object {$_.$Message -notlike "*Monitis*"}另外,我如何在where-object上加入多个条件?
在我的脚本中,我得到了关于-and语句的错误:
$getEventLog = Get-Eventlog -log application -after ((get-date).addMinutes($minutes*-1)) -EntryType Error
# list of events to exclude
$getEventLogFiltered = $getEventLog | where-object {$_.Message -notlike "Monitis*"
-and $_.Message -notlike "*MQQueueDepthMonitor.exe*"
}
$tableFragment = $getEventLogFiltered | ConvertTo-Html -fragment错误:
-and : The term '-and' is not recognized as the name of a cmdlet, function, script file, or operable program. Check
the spelling of the name, or if a path was included, verify that the path is correct and try again.
At D:\scripts\EventLogExtract2.ps1:24 char:40
+ -and $_.Message -notlike "*MQQueueDepthMo ...
+ ~~~~发布于 2013-06-26 00:29:12
在你的第二个代码片段中,去掉"Message“前的美元符号。读起来像下面这样。如果您使用的是PowerShell ISE,您将看到"Message“应为黑色而不是红色。
Get-Eventlog -log application -after ((get-date).addMinutes(-360)) -EntryType Error | where-object {$_.Message -notlike "*Monitis*"}对于第三个代码片段,我在Where-Object过滤器中开始换行之前放置了一个grave accent。这会告诉PowerShell您是在继续一行,而不是开始一个新行。此外,在PowerShell ISE中,比较运算符(-and和-notlike)从蓝色和黑色变为灰色。
$getEventLog = Get-Eventlog -log application -after ((get-date).addMinutes($minutes*-1)) -EntryType Error
# list of events to exclude
$getEventLogFiltered = $getEventLog | where-object {$_.Message -notlike "Monitis*" `
-and $_.Message -notlike "*MQQueueDepthMonitor.exe*"
}
$tableFragment = $getEventLogFiltered | ConvertTo-Html -fragment发布于 2015-10-02 21:23:42
数据简化:((get-date).addMinutes($minutes*-1))具有与((get-date).addMinutes(-1))相同的输出和与(get-date).addMinutes(-1)相同的输出
另外,我发现addDays(-1)更有用。
https://stackoverflow.com/questions/17195184
复制相似问题