PowerShell 新手

New to PowerShell

我对 PowerShell 非常陌生,我正在尝试创建一个脚本,该脚本看起来会被认为是系统事件日志,并提取与错误、详细和警告匹配的项目;然后我想将它们导出到 CSV 文件。

我能够获取为 $errorlog、$verboselog 和 $warninglog 创建的每个变量(如下所示)。

$errorlog = Get-EventLog system -Newest 200 | Where-Object {$_.entryType -Match 'Error'}
$verboselog = Get-EventLog system -Newest 200 | Where-Object {$_.entryType -Match 'Verbose'}
$warninglog = Get-EventLog system -Newest 200 | Where-Object {$_.entryType -Match 'Warning'}

当我继续尝试将它们导出到一个 CSV 文件时,它只显示 $errorlog。根据我从各种网站收集到的信息,我正在使用的命令应该可以正常工作。

$errorlog,$verboselog,$waninglog | Export-CSV -inputobject  -path 'C:\service\test.CSV'

有人告诉我它是否缺少“-inputobject”,所以我移动了变量,如下所示。

Export-CSV -inputobject  $errorlog,$verboselog,$warninglog  -path 'C:\service\test.CSV'

它导出时没有错误,但它没有在文件中显示我想要的数据。

预先感谢您的帮助。

$errorlog = Get-EventLog system -Newest 200| Where-Object {$_.entryType -eq 'Error'}
$verboselog = Get-EventLog system -Newest 200| Where-Object {$_.entryType -eq 'Verbose'}
$warninglog = Get-EventLog system -Newest 200| Where-Object {$_.entryType -eq 'Warning'}
$errorlog+$verboselog+$warninglog | Export-Csv C:\service\test.CSV

我用 -eq 替换了 -match 并删除了 inputobject 开关。我还将逗号更改为加号以连接结果。这对我有用。