Powershell:无法将'System.Object []'转换为'System.String'类型(Powershell: Cannot convert 'System.Object[]' to the type 'System.String')

当我运行以下代码时,我收到消息“无法将System.Object []'转换为'System.String'”类型。 如何将事件日志列表传递回get-eventlog?

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

Get-EventLog:无法将'System.Object []'转换为参数'LogName'所需的'System.String'类型。

感谢您的帮助

When I run the following code i receive the message "cannot convert 'System.Object[]' to the type 'System.String'". How do i 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'.

your help is appreciated

最满意答案

LogName是Get-EventLog的必需参数,您必须提供它,除非您尝试使用-list执行列表。 此外,它期望一个字符串和第二行给出错误,因为您传入一个数组。

除此之外,还不清楚你要对这些陈述做些什么。

我想你想要的东西是这样的:

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

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 }Powershell:无法将'System.Object []'转换为'System.String'类型(Powershell: Cannot convert 'System.Object[]' to the type 'System.String')

当我运行以下代码时,我收到消息“无法将System.Object []'转换为'System.String'”类型。 如何将事件日志列表传递回get-eventlog?

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

Get-EventLog:无法将'System.Object []'转换为参数'LogName'所需的'System.String'类型。

感谢您的帮助

When I run the following code i receive the message "cannot convert 'System.Object[]' to the type 'System.String'". How do i 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'.

your help is appreciated

最满意答案

LogName是Get-EventLog的必需参数,您必须提供它,除非您尝试使用-list执行列表。 此外,它期望一个字符串和第二行给出错误,因为您传入一个数组。

除此之外,还不清楚你要对这些陈述做些什么。

我想你想要的东西是这样的:

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

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 }