PowerShell:Get-Winevent 不适用于 foreach 循环中的多个对象
我启用了审核事件组策略,然后将我的测试帐户添加到 Groupname11。
当我尝试在没有注释掉其他组名称的情况下运行它时,我没有从 $Events
中得到任何信息。
我不明白我做错了什么?
$Groups = @(
#"Groupname8"
#"Groupname9"
#"AGroupname10"
"Groupname11"
#"Groupname12"
)
Foreach ($Group in $Groups){
$Events = Get-WinEvent -FilterHashtable @{logname = 'Security'; ID = 4728; } | Where-Object {$_.Properties.Value -like "*$($Groups)*"}
}
$Events
I enabled the audit event group policy and then I added my test account to Groupname11.
When I try to run this without the other group names commented out I don't get anything from $Events
.
I don't understand what I am doing wrong?
$Groups = @(
#"Groupname8"
#"Groupname9"
#"AGroupname10"
"Groupname11"
#"Groupname12"
)
Foreach ($Group in $Groups){
$Events = Get-WinEvent -FilterHashtable @{logname = 'Security'; ID = 4728; } | Where-Object {$_.Properties.Value -like "*$($Groups)*"}
}
$Events
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您当前正在循环的每次迭代中覆盖
$Events
。将分配移出循环,以便捕获
$Events
中所有组的事件:You're currently overwriting
$Events
on each iteration of the loop.Move the assignment out of the loop so you capture the events for all the groups in
$Events
: