$AuditSuccess = Import-Csv -Path G:\LabLog.csv | Where-Object { $_.Keywords -like "Audit Success" } | Measure-Object | Select-Object count
$AuditFailure = Import-Csv -Path G:\LabLog.csv | Where-Object { $_.Keywords -like "Audit Failure" } | Measure-Object | Select-Object count
$AuditTotal = $AuditSuccess + $AuditFailure
$EventID1 = Import-Csv -Path G:\LabLog.csv | sort | group Keywords | sort $_.EventID | select EventID -last 1
$EventID2 = Import-Csv -Path G:\LabLog.csv | sort | group Keywords | sort $_.EventID | select EventID -last 1
Write-Host "Number of Audit Failures:" $AuditFailure "failures of" $AuditTotal "entries"
Write-Host "Most Common Event ID:" $EventID1
Write-Host "Number of Audit Successes:" $AuditSuccess "successes of" $AuditTotal "entries"
Write-Host "Most Common Event ID:" $EventID2
我对 Powershell 还很陌生,并尝试将其用于分配我需要导入 csv 日志,然后从中提取特定信息,在这种情况下,所有日志中的失败和成功次数以及最常见的事件 ID来自失败和成功。
代码的 AuditFailure 和 AuditSuccess 部分在某种程度上起作用,尽管结果显示为 {count = ##} 而不是数字。真正的问题在于 AuditTotal 和 EventID,它们在总计的情况下没有产生任何结果,或者在 EventID 的情况下给出的结果为空白。
我不知道这些是否是为此使用的最佳命令,并且愿意提供任何帮助来解决这个问题。
Method invocation failed because [System.Management.Automation.PSObject] does
not contain a method named 'op_Addition'.
At line:5 char:1
+ $AuditTotal = $AuditSuccess + $AuditFailure
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (op_Addition:String) [],
RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Number of Audit Failures: @{Count=13} failures of entries
Most Common Event ID: @{EventID=}
Number of Audit Successes: @{Count=6480} successes of entries
Most Common Event ID: @{EventID=}
抱歉,这是错误输出
Number of Audit Failures: 2469 failures of 19247 entries
Most common Event ID: 5038
Number of Audit Successes: 16778 successes of 19247 entries
Most common Event ID: 4624
这是它应该看起来的样子,尽管数字是不同的