[英]How can I select Event log by their InstanceID
I would like to get all EventLog entries concerning the system and an error. 我想获取有关系统和错误的所有EventLog条目。 And among those entries I want to select them by their specific InstanceID.
在这些条目中,我想通过它们的特定InstanceID选择它们。
I am going with aa pipe where I slim down the filter but I don't know how to compare the InstanceID with the value of the InstanceID I want. 我正在使用一个管道,在其中过滤器变薄,但是我不知道如何将InstanceID与我想要的InstanceID的值进行比较。
$sysLog = Get-EventLog -LogName System -EntryType Error |
Where-Object{$_.InstanceId = 10016}
+ ... LogName System -EntryType Error | Where-Object{$_.InstanceId = 10016} + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation : (:) [], RuntimeException + FullyQualifiedErrorId : PropertyAssignmentException
i think that code work : 我认为代码工作:
$sysLog = Get-EventLog -LogName System -EntryType Error | Where-Object{$_.InstanceId -eq 10016}
$sysLog
see : https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-6 请参阅: https : //docs.microsoft.com/zh-cn/powershell/module/microsoft.powershell.core/about/about_comparison_operators?view=powershell-6
EDIT example with export to log file : 导出到日志文件的EDIT示例:
Function WriteEventLogFile ([string] $pathToWriteLog, [string] $InstanceId){
$sysLogItems = Get-EventLog -LogName System -EntryType Error | Where-Object {$_.InstanceId -eq $InstanceId}
# write-host $sysLogItems
$sysLogItems | Export-Csv -Path $pathToWriteLog -NoTypeInformation
}
WriteEventLogFile -pathToWriteLog:"C:\Temp\envent_export.log" -InstanceId:"10016"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.