在交互模式下,這個工程:如何設置Powershell的地方,對象過濾事件日誌
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*"}
另外,我該如何在多個條件上放置對象?
在-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 ...
+ ~~~~
今天,第一部分似乎正在工作(-notlike)。當我昨天運行它時,可能還有其他時間問題或者-after子句的問題。 – NealWalters
顯然,你不能在每個之間放一個換行符?如果我把所有的話和陳述都放在一行上,它似乎就行得通。但是這使代碼很難讀取/維護。我最終可能會有10條語句。也許我應該只使用連續的管道? – NealWalters