スクリプトの入力として変数の出力を使用する際に問題があります。私はこの実行するとPowershell Get-Eventlogオブジェクト出力の問題
は:
$listoflogs = Get-EventLog -List | Select "Log"
$listoflogss | % { Get-EventLog -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
を私はそれが入力としてオブジェクトとの契約をdoesntのことを理解し、次のエラーが発生し、得ました。
Get-EventLog : The event log '@{Log=System}' on computer '.' does not exist. At line:5 char:31
+ $listoflogs | % { Get-EventLog <<<< -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
+ CategoryInfo : NotSpecified: (:) [Get-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand
Get-EventLog : The event log '@{Log=ThinPrint Diagnostics}' on computer '.' does not exist. At line:5 char:31
+ $listoflogs | % { Get-EventLog <<<< -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
+ CategoryInfo : NotSpecified: (:) [Get-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand
Get-EventLog : The event log '@{Log=Windows PowerShell}' on computer '.' does not exist. At line:5 char:31
+ $listoflogs | % { Get-EventLog <<<< -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
+ CategoryInfo : NotSpecified: (:) [Get-EventLog], InvalidOperationException
+ FullyQualifiedErrorId : System.InvalidOperationException,Microsoft.PowerShell.Commands.GetEventLogCommand
次に、オブジェクトを文字列に変換するスクリプトを変更しましたが、依然として私が望む出力を得ることができません。
$listoflogs = Get-EventLog -List | Select "Log"
$listoflogss = ($listoflogs | Out-String)
$listoflogss | % { Get-EventLog -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
Get-EventLog : Event log names must consist of printable characters and cannot contain \, *, ?, or space s At line:7 char:32
+ $listoflogss | % { Get-EventLog <<<< -LogName $_ | Where-Object {$_.EntryType -Match "Error"} }
+ CategoryInfo : NotSpecified: (:) [Get-EventLog], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Commands.GetEventLogCommand
私は間違っていることを知っていませんが、この作業を達成するのが良いですか?それでも、オブジェクト出力をスクリプトの読み込み可能な文字列に変換するこの概念を理解することはできません。
こんにちは、 '$ listoflogs =のGet-EventLogに - リストを試す|:
はまた、このようなエラーを抑制している可能性がSelect-Object -ExpandProperty Log'を選択します。 – sodawillow