Search code examples
stringpowershellevent-log

Conversion Error Generated When Using Get-EventLog


When I run the following code I get the error message shown below. How does one pass the event log list back to get-eventlog?

$EventLogList = Get-EventLog | Select-Object -ExpandProperty log
Get-evenlog -log $eventloglist

Get-EventLog : Cannot convert 'System.Object[]' to the type 'System.String' required by parameter 'LogName'.


Solution

  • LogName is a mandatory parameter to Get-EventLog and you have to supply it, unless you are trying to do a list with -list. Also, it expects a string and the second line is giving the error because you are passing in an array.

    Apart from that, it is also not clear what you are trying to do with the statements.

    I suppose you want something like:

    get-eventlog -list | %{ get-eventlog -log $_.log }