I’m trying to exclude certain events, some with specific messages. When I exclude Event IDs, it works as expected. When I exclude Event ID with specific Message, it works as expected. But, If I try to exclude a Event IDs and also a Specific Event ID with a Specific Message, it still returns the Event ID & Message I’m trying to exclude…
This Works as expected…
$GetData = { [PSCustomObject]@{ EventLog = $(Get-EventLog -Log "Application" -After (Get-Date).AddDays(-1) -EntryType Error,Warning | ` ? { $_.eventID -ne 1300 -and $_.Message -notcontains "*SQLsafe Backup Service version*" } | Select TimeGenerated,Category,EventID,EntryType,Message)} } Invoke-Command -ComputerName ServerName -ScriptBlock $GetData -ErrorAction SilentlyContinue
THis works as expected…
$GetData = { [PSCustomObject]@{ EventLog = $(Get-EventLog -Log "Application" -After (Get-Date).AddDays(-1) -EntryType Error,Warning | ` ? { { $_.eventID -NotMatch '9245|1008' } } | Select TimeGenerated,Category,EventID,EntryType,Message)} } Invoke-Command -ComputerName ServerName -ScriptBlock $GetData -ErrorAction SilentlyContinue
But this doesn’t…it still returns the 1300 events with the SqlSafe message.
$GetData = { [PSCustomObject]@{ EventLog = $(Get-EventLog -Log "Application" -After (Get-Date).AddDays(-1) -EntryType Error,Warning | ` ? { { $_.eventID -NotMatch '9245|1008' } -Or { $_.eventID -Ne 1300 -And $_.Message -notcontains "*SQLsafe Backup Service version*" } } | Select TimeGenerated,Category,EventID,EntryType,Message)} } Invoke-Command -ComputerName ServerName -ScriptBlock $GetData -ErrorAction SilentlyContinue
What am I doing wrong ?
*I’m using the PSCustomObject as I’ve a few other commands being run on the servers are the same time.