Powershell写入事件日志写入重复条目
我使用PowerShell解析一些日志,并将结果写入专用的Windows日志。我遇到了这样一个问题,Powershell写入事件日志写入重复条目,powershell,Powershell,我使用PowerShell解析一些日志,并将结果写入专用的Windows日志。我遇到了这样一个问题,Write EventLog有时会以1秒的延迟创建两次相同的条目 我不明白为什么会这样您也遇到过这个问题吗?您是如何解决的 下面是我的代码我添加了一个debug,它将内容写入文本文件。在文本文件中,只有1倍的内容 Function Publish-EventLog { param ( $logInfos ) $eventl
Write EventLog
有时会以1秒的延迟创建两次相同的条目
我不明白为什么会这样您也遇到过这个问题吗?您是如何解决的
下面是我的代码我添加了一个debug
,它将内容写入文本文件。在文本文件中,只有1倍的内容
Function Publish-EventLog {
param (
$logInfos
)
$eventlogs = @()
Get-EventLog -List | Select-Object Log | ForEach-Object { $eventlogs += $_.Log }
if ($eventlogs -contains('ABLogs')) {
Write-Host "Log already exists."
} else {
New-EventLog -LogName ABLogs -Source ABComputer
}
Write-EventLog -LogName ABLogs -Source ABComputer -EntryType $([string]$logInfos.WinEventType) -EventId $($logInfos.ABEventId) -Message $($logInfos.Details)
$runTime = Get-Date -Format "yyyy-MM-dd_HH-mm-ss"
"Function, Publish: time : $($runTime)" | Out-File $logFile -Append
"Function, Publish: logInfos.Details : $($logInfos.Details)" | Out-File $logFile -Append
} #End Function Publish-EventLog