2016-03-07 17 views
0

这项工作对我来说:获取-WinEvent -FilterHashTable包含多个ID的一个变量不工作

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = 4625,4740} 

(....结果我想到...)

这工作:

$EventId = "4625" 

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventId} 

这不起作用:

$EventId = "4625,4740" 

Get-WinEvent -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventId} 

尔ror ...

Get-WinEvent : No events were found that match the specified selection criteria. 
At line:1 char:13 
+ Get-WinEvent <<<< -FilterHashTable @{Logname = "ForwardedEvents" ; ID = $EventIds} 
+ CategoryInfo   : ObjectNotFound: (:) [Get-WinEvent], Exception 
+ FullyQualifiedErrorId : NoMatchingEventsFound,Microsoft.PowerShell.Commands.GetWinEventCommand 

任何人都可以帮忙吗?

回答

3

在你的例子中,有多个ID,你正在做两件不同的事情。

$EventId = "4625,4740"定义了一个字符串。您的工作示例使用以逗号分隔的数字定义的整数数组。

只需将其更改为$EventId = 4625,4740(删除引号)即可使用。纵观documentation for Get-WinEvent and the -FilterHashTable我们看到:

-- ID=<Int32[]> 

所以它期待一个数组,而不是一个字符串。

+1

谢谢马特。很棒。 – adriansroaming