Html 从输出中筛选出某些事件日志的问题

Html 从输出中筛选出某些事件日志的问题,html,powershell,Html,Powershell,因此,我编写了一个小脚本,将我的服务器最近24小时的事件日志发送到一封漂亮的HTML电子邮件中,以避免我必须登录到每个服务器,等等。它工作得很好,只是我们的一些应用程序产生了大量我想过滤掉的事件 我已经设法使用where语句来过滤掉一个事件,但是当我尝试向其中添加另一个事件ID时,它无法按预期工作 下面是我的代码片段: $ApplicationEventsReport = @() $ApplicationEvents = Get-EventLog -ComputerName $computer

因此,我编写了一个小脚本,将我的服务器最近24小时的事件日志发送到一封漂亮的HTML电子邮件中,以避免我必须登录到每个服务器,等等。它工作得很好,只是我们的一些应用程序产生了大量我想过滤掉的事件

我已经设法使用where语句来过滤掉一个事件,但是当我尝试向其中添加另一个事件ID时,它无法按预期工作

下面是我的代码片段:

$ApplicationEventsReport = @()
$ApplicationEvents = Get-EventLog -ComputerName $computer -LogName Application -EntryType Error,Warning -After (Get-Date).AddDays(-1) | where {$_.EventID -ne 1530}

foreach ($event in $ApplicationEvents) {
        $row = New-Object -Type PSObject -Property @{
                TimeGenerated = $event.TimeGenerated
                EntryType = $event.EntryType
                Source = $event.Source
                Message = $event.Message
                EventID = $event.InstanceID
        }
        $ApplicationEventsReport += $row
}

$ApplicationEventsReport = $ApplicationEventsReport | ConvertTo-Html -Fragment
您会注意到在get eventlog行的末尾有一个where部分,如果有意义的话,-ne是ID

我尝试通过以下方式添加另一个:

where {$_.EventID -ne 1530 -or $_.EventID -ne 3221229571}

where {($_.EventID -ne 1530) -or ($_.EventID -ne 3221229571)}

where {$_.EventID -ne 1530} | where {$_.EventID -ne 3221229571}

where {$_.EventID -ne 1530} -or {$_.EventID -ne 3221229571}
然而,所有这些工作要么完全忽略它,要么仍然只处理第一个(1530)


有没有想过为什么会失败,如果我在我的机器上本地运行该行,它们似乎都能工作?只有当我重新放入脚本时,它似乎才会崩溃?

我想我看到了一些潜在的问题。如果我们从我的本地计算机上看一些事件

EventID InstanceId Message                                                                                                                                   
------- ---------- -------                                                                                                                                   
   1202 2147484850 Security policies were propagated with warning....                                                                                        
      0          0 The description for Event ID '0' in Source 'gupdate' cannot be found.  The local computer may not have the necessary registry informati...
   1001       1001 Fault bucket , type 0...                                                                                                                  
   1001       1001 Fault bucket , type 0...                                                                                                                  
   1003 1073742827 The Software Protection service has completed licensing status check....                                                                  
   1202 2147484850 Security policies were propagated with warning....                                                                                        
     32 1073741856 The store ...                                        
     32 1073741856 The store   ....
我看到的数字与您的类似,但不包括实例ID。所以一个简单的改变就是这样

Where-Object {$_.EventID -ne 1530 -and $_.InstanceID -ne 3221229571}
您应该使用
-和
,因为如果要筛选的记录仅符合其中一个条件,则使用-或可能会导致问题

如果要筛选的记录很多,那么可以将这些值存储在数组中,以便在
Where
子句中使用

$eventsToIgnore = "1004","1500","10001"
$instanceIDsToIgnore = "3221229571","2147484850"

#.... blah blah... other stuff

Where-Object {$eventsToIgnore -notcontains $_.EventID -and $instanceIDsToIgnore -notcontains $_.InstanceID}

如果只保留
{$\.EventID-ne 3221229571}
-将作为单个条件本身工作,该怎么办?较长的数字看起来像一个实例ID<代码>在哪里{$\事件ID-ne 1530-和$\实例ID-ne 3221229571}工作?根据您试图过滤的内容,创建数组和使用
-notcontains
可能是首选。如果这些值不适用于同一事件条目,则使用
-或
可能会给您带来麻烦,并可能会阻止它们被排除。Perfect Matt,我使用了arrays方法并将其传送到where and bingo!我猜我也对-或和-以及,在我的头脑中-感到困惑,这意味着它需要两个值,但我猜它是排除的,所以排除其中一个。。。这是漫长的一天!再次感谢